/*
 * Copyright 2021-2024 The PySCF Developers. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

__global__
static void GINTint2e_ip1_jk_kernel_0021(GINTEnvVars envs, JKMatrix jk,
                                    BasisProdOffsets offsets)
{
    int ntasks_ij = offsets.ntasks_ij;
    int ntasks_kl = offsets.ntasks_kl;
    int task_ij = blockIdx.x * blockDim.x + threadIdx.x;
    int task_kl = blockIdx.y * blockDim.y + threadIdx.y;
    if (task_ij >= ntasks_ij || task_kl >= ntasks_kl) {
        return;
    }
    int bas_ij = offsets.bas_ij + task_ij;
    int bas_kl = offsets.bas_kl + task_kl;
    double norm = envs.fac;
    double omega = envs.omega;
    int *bas_pair2bra = c_bpcache.bas_pair2bra;
    int *bas_pair2ket = c_bpcache.bas_pair2ket;
    int ish = bas_pair2bra[bas_ij];
    int jsh = bas_pair2ket[bas_ij];
    int ksh = bas_pair2bra[bas_kl];
    int lsh = bas_pair2ket[bas_kl];
    int nprim_ij = envs.nprim_ij;
    int nprim_kl = envs.nprim_kl;
    int prim_ij = offsets.primitive_ij + task_ij * nprim_ij;
    int prim_kl = offsets.primitive_kl + task_kl * nprim_kl;

    double* __restrict__ a12 = c_bpcache.a12;
    double* __restrict__ e12 = c_bpcache.e12;
    double* __restrict__ x12 = c_bpcache.x12;
    double* __restrict__ y12 = c_bpcache.y12;
    double* __restrict__ z12 = c_bpcache.z12;
    double * __restrict__ i_exponent = c_bpcache.a1;
    double * __restrict__ j_exponent = c_bpcache.a2;

    int ij, kl;
    int prim_ij0, prim_ij1, prim_kl0, prim_kl1;
    int nbas = c_bpcache.nbas;
    double* __restrict__ bas_x = c_bpcache.bas_coords;
    double* __restrict__ bas_y = bas_x + nbas;
    double* __restrict__ bas_z = bas_y + nbas;

    double gout0 = 0;
    double gout1 = 0;
    double gout2 = 0;
    double gout3 = 0;
    double gout4 = 0;
    double gout5 = 0;
    double gout6 = 0;
    double gout7 = 0;
    double gout8 = 0;
    double gout9 = 0;
    double gout10 = 0;
    double gout11 = 0;
    double gout12 = 0;
    double gout13 = 0;
    double gout14 = 0;
    double gout15 = 0;
    double gout16 = 0;
    double gout17 = 0;
    double gout18 = 0;
    double gout19 = 0;
    double gout20 = 0;
    double gout21 = 0;
    double gout22 = 0;
    double gout23 = 0;
    double gout24 = 0;
    double gout25 = 0;
    double gout26 = 0;
    double gout27 = 0;
    double gout28 = 0;
    double gout29 = 0;
    double gout30 = 0;
    double gout31 = 0;
    double gout32 = 0;
    double gout33 = 0;
    double gout34 = 0;
    double gout35 = 0;
    double gout36 = 0;
    double gout37 = 0;
    double gout38 = 0;
    double gout39 = 0;
    double gout40 = 0;
    double gout41 = 0;
    double gout42 = 0;
    double gout43 = 0;
    double gout44 = 0;
    double gout45 = 0;
    double gout46 = 0;
    double gout47 = 0;
    double gout48 = 0;
    double gout49 = 0;
    double gout50 = 0;
    double gout51 = 0;
    double gout52 = 0;
    double gout53 = 0;
    double gout54 = 0;
    double gout55 = 0;
    double gout56 = 0;
    double gout57 = 0;
    double gout58 = 0;
    double gout59 = 0;
    double gout60 = 0;
    double gout61 = 0;
    double gout62 = 0;
    double gout63 = 0;
    double gout64 = 0;
    double gout65 = 0;
    double gout66 = 0;
    double gout67 = 0;
    double gout68 = 0;
    double gout69 = 0;
    double gout70 = 0;
    double gout71 = 0;
    double gout72 = 0;
    double gout73 = 0;
    double gout74 = 0;
    double gout75 = 0;
    double gout76 = 0;
    double gout77 = 0;
    double gout78 = 0;
    double gout79 = 0;
    double gout80 = 0;
    double gout81 = 0;
    double gout82 = 0;
    double gout83 = 0;
    double gout84 = 0;
    double gout85 = 0;
    double gout86 = 0;
    double gout87 = 0;
    double gout88 = 0;
    double gout89 = 0;
    double gout90 = 0;
    double gout91 = 0;
    double gout92 = 0;
    double gout93 = 0;
    double gout94 = 0;
    double gout95 = 0;
    double gout96 = 0;
    double gout97 = 0;
    double gout98 = 0;
    double gout99 = 0;
    double gout100 = 0;
    double gout101 = 0;
    double gout102 = 0;
    double gout103 = 0;
    double gout104 = 0;
    double gout105 = 0;
    double gout106 = 0;
    double gout107 = 0;

    double xi = bas_x[ish];
    double yi = bas_y[ish];
    double zi = bas_z[ish];
    double ABx = xi - bas_x[jsh];
    double ABy = yi - bas_y[jsh];
    double ABz = zi - bas_z[jsh];
    double xk = bas_x[ksh];
    double yk = bas_y[ksh];
    double zk = bas_z[ksh];
    double CDx = xk - bas_x[lsh];
    double CDy = yk - bas_y[lsh];
    double CDz = zk - bas_z[lsh];
    prim_ij0 = prim_ij;
    prim_ij1 = prim_ij + nprim_ij;
    prim_kl0 = prim_kl;
    prim_kl1 = prim_kl + nprim_kl;
    double rw[6];
    int irys;
    for (ij = prim_ij0; ij < prim_ij1; ++ij) {
        double alpha = i_exponent[ij];
        double beta = j_exponent[ij];
        double aij = a12[ij];
        double eij = e12[ij];
        double xij = x12[ij];
        double yij = y12[ij];
        double zij = z12[ij];
    for (kl = prim_kl0; kl < prim_kl1; ++kl) {
        double akl = a12[kl];
        double ekl = e12[kl];
        double xkl = x12[kl];
        double ykl = y12[kl];
        double zkl = z12[kl];
        double xijxkl = xij - xkl;
        double yijykl = yij - ykl;
        double zijzkl = zij - zkl;
        double aijkl = aij + akl;
        double a1 = aij * akl;
        double a0 = a1 / aijkl;
        double theta = omega > 0.0 ? omega * omega / (omega * omega + a0) : 1.0; 
        a0 *= theta;
        double x = a0 * (xijxkl * xijxkl + yijykl * yijykl + zijzkl * zijzkl);
        double fac = norm * eij * ekl * sqrt(a0 / (a1 * a1 * a1));
        //double fac = norm * eij * ekl / (sqrt(aijkl) * a1);

        GINTrys_root<3>(x, rw);
        GINTscale_u<3>(rw, theta);
      for (irys = 0; irys < 3; ++irys) {
            double weight0 = rw[irys+3] * fac;
            double root0 = rw[irys];
            double u2 = a0 * root0;
            double tmp4 = .5 / (u2 * aijkl + a1);
            double B00 = u2 * tmp4;
            double tmp1 = 2 * B00;

            double tmp2 = tmp1 * akl;
            double C00x = xij - xi - tmp2 * xijxkl;
            double C00y = yij - yi - tmp2 * yijykl;
            double C00z = zij - zi - tmp2 * zijzkl;
            double B01 = B00 + tmp4 * aij;
            double tmp3 = tmp1 * aij;
            double D00x = xkl - xk + tmp3 * xijxkl;
            double D00y = ykl - yk + tmp3 * yijykl;
            double D00z = zkl - zk + tmp3 * zijzkl;

            double g1 = B00+(C00x*D00x);
            double g2 = B01+D00x*D00x;
            double g3 = 2*B00*D00x;
            double g4 = C00x*g2;
            double g5 = g3+g4;
            double g6 = ABx+C00x;
            double g7 = g6*D00x;
            double g8 = B00+g7;
            double g9 = g6*g2;
            double g10 = g3+g9;
            double g11 = CDx+D00x;
            double g12 = C00x*g11;
            double g13 = B00+g12;
            double g15 = B01+(D00x*g11);
            double g20 = B00*(CDx+(2*D00x));
            double g21 = (B01*C00x)+(C00x*D00x*g11)+g20;
            double g23 = 3*D00x;
            double g24 = CDx+g23;
            double g26 = (D00x*D00x*g11)+(B01*g24);
            double g27 = 3*B00*B01;
            double g31 = (2*CDx)+g23;
            double g33 = g27+(C00x*D00x*D00x*g11)+(B01*C00x*g24)+(B00*D00x*g31);
            double g35 = B00+(g6*g11);
            double g37 = g20+(g6*g15);
            double g39 = 3*B01;
            double g43 = (g6*g26)+(B00*(g39+(D00x*g31)));
            double g45 = B00+(C00y*D00y);
            double g46 = B01+D00y*D00y;
            double g47 = 2*B00*D00y;
            double g49 = g47+(C00y*g46);
            double g50 = ABy+C00y;
            double g52 = B00+(g50*D00y);
            double g54 = g47+(g50*g46);
            double g55 = CDy+D00y;
            double g57 = B00+(C00y*g55);
            double g59 = B01+(D00y*g55);
            double g64 = B00*(CDy+(2*D00y));
            double g65 = (B01*C00y)+(C00y*D00y*g55)+g64;
            double g67 = 3*D00y;
            double g68 = CDy+g67;
            double g70 = (D00y*D00y*g55)+(B01*g68);
            double g74 = (2*CDy)+g67;
            double g76 = g27+(C00y*D00y*D00y*g55)+(B01*C00y*g68)+(B00*D00y*g74);
            double g78 = B00+(g50*g55);
            double g80 = g64+(g50*g59);
            double g85 = (g50*g70)+(B00*(g39+(D00y*g74)));
            double g87 = B00+(C00z*D00z);
            double g88 = B01+D00z*D00z;
            double g89 = 2*B00*D00z;
            double g91 = g89+(C00z*g88);
            double g92 = ABz+C00z;
            double g94 = B00+(g92*D00z);
            double g96 = g89+(g92*g88);
            double g97 = CDz+D00z;
            double g99 = B00+(C00z*g97);
            double g101 = B01+(D00z*g97);
            double g106 = B00*(CDz+(2*D00z));
            double g107 = (B01*C00z)+(C00z*D00z*g97)+g106;
            double g109 = 3*D00z;
            double g110 = CDz+g109;
            double g112 = (D00z*D00z*g97)+(B01*g110);
            double g116 = (2*CDz)+g109;
            double g118 = g27+(C00z*D00z*D00z*g97)+(B01*C00z*g110)+(B00*D00z*g116);
            double g120 = B00+(g92*g97);
            double g122 = g106+(g92*g101);
            double g127 = (g92*g112)+(B00*(g39+(D00z*g116)));

            gout0 += (2*alpha*g33) * weight0;
            gout1 += (2*alpha*g5) * (g55) * weight0;
            gout2 += (2*alpha*g5) * (g97) * weight0;
            gout3 += (2*alpha*g21) * (D00y) * weight0;
            gout4 += (2*alpha*g1) * (g59) * weight0;
            gout5 += (2*alpha*g1) * (D00y) * (g97) * weight0;
            gout6 += (2*alpha*g21) * (D00z) * weight0;
            gout7 += (2*alpha*g1) * (g55) * (D00z) * weight0;
            gout8 += (2*alpha*g1) * (g101) * weight0;
            gout9 += (2*alpha*g13) * (g46) * weight0;
            gout10 += (2*alpha*C00x) * (g70) * weight0;
            gout11 += (2*alpha*C00x) * (g46) * (g97) * weight0;
            gout12 += (2*alpha*g13) * (D00y) * (D00z) * weight0;
            gout13 += (2*alpha*C00x) * (g59) * (D00z) * weight0;
            gout14 += (2*alpha*C00x) * (D00y) * (g101) * weight0;
            gout15 += (2*alpha*g13) * (g88) * weight0;
            gout16 += (2*alpha*C00x) * (g55) * (g88) * weight0;
            gout17 += (2*alpha*C00x) * (g112) * weight0;
            gout18 += (g26) * (2*alpha*C00y) * weight0;
            gout19 += (g2) * (2*alpha*g57) * weight0;
            gout20 += (g2) * (2*alpha*C00y) * (g97) * weight0;
            gout21 += (g15) * (2*alpha*g45) * weight0;
            gout22 += (D00x) * (2*alpha*g65) * weight0;
            gout23 += (D00x) * (2*alpha*g45) * (g97) * weight0;
            gout24 += (g15) * (2*alpha*C00y) * (D00z) * weight0;
            gout25 += (D00x) * (2*alpha*g57) * (D00z) * weight0;
            gout26 += (D00x) * (2*alpha*C00y) * (g101) * weight0;
            gout27 += (g11) * (2*alpha*g49) * weight0;
            gout28 += (2*alpha*g76) * weight0;
            gout29 += (2*alpha*g49) * (g97) * weight0;
            gout30 += (g11) * (2*alpha*g45) * (D00z) * weight0;
            gout31 += (2*alpha*g65) * (D00z) * weight0;
            gout32 += (2*alpha*g45) * (g101) * weight0;
            gout33 += (g11) * (2*alpha*C00y) * (g88) * weight0;
            gout34 += (2*alpha*g57) * (g88) * weight0;
            gout35 += (2*alpha*C00y) * (g112) * weight0;
            gout36 += (g26) * (2*alpha*C00z) * weight0;
            gout37 += (g2) * (g55) * (2*alpha*C00z) * weight0;
            gout38 += (g2) * (2*alpha*g99) * weight0;
            gout39 += (g15) * (D00y) * (2*alpha*C00z) * weight0;
            gout40 += (D00x) * (g59) * (2*alpha*C00z) * weight0;
            gout41 += (D00x) * (D00y) * (2*alpha*g99) * weight0;
            gout42 += (g15) * (2*alpha*g87) * weight0;
            gout43 += (D00x) * (g55) * (2*alpha*g87) * weight0;
            gout44 += (D00x) * (2*alpha*g107) * weight0;
            gout45 += (g11) * (g46) * (2*alpha*C00z) * weight0;
            gout46 += (g70) * (2*alpha*C00z) * weight0;
            gout47 += (g46) * (2*alpha*g99) * weight0;
            gout48 += (g11) * (D00y) * (2*alpha*g87) * weight0;
            gout49 += (g59) * (2*alpha*g87) * weight0;
            gout50 += (D00y) * (2*alpha*g107) * weight0;
            gout51 += (g11) * (2*alpha*g91) * weight0;
            gout52 += (g55) * (2*alpha*g91) * weight0;
            gout53 += (2*alpha*g118) * weight0;
            gout54 += (2*beta*g43) * weight0;
            gout55 += (2*beta*g10) * (g55) * weight0;
            gout56 += (2*beta*g10) * (g97) * weight0;
            gout57 += (2*beta*g37) * (D00y) * weight0;
            gout58 += (2*beta*g8) * (g59) * weight0;
            gout59 += (2*beta*g8) * (D00y) * (g97) * weight0;
            gout60 += (2*beta*g37) * (D00z) * weight0;
            gout61 += (2*beta*g8) * (g55) * (D00z) * weight0;
            gout62 += (2*beta*g8) * (g101) * weight0;
            gout63 += (2*beta*g35) * (g46) * weight0;
            gout64 += (2*beta*g6) * (g70) * weight0;
            gout65 += (2*beta*g6) * (g46) * (g97) * weight0;
            gout66 += (2*beta*g35) * (D00y) * (D00z) * weight0;
            gout67 += (2*beta*g6) * (g59) * (D00z) * weight0;
            gout68 += (2*beta*g6) * (D00y) * (g101) * weight0;
            gout69 += (2*beta*g35) * (g88) * weight0;
            gout70 += (2*beta*g6) * (g55) * (g88) * weight0;
            gout71 += (2*beta*g6) * (g112) * weight0;
            gout72 += (g26) * (2*beta*g50) * weight0;
            gout73 += (g2) * (2*beta*g78) * weight0;
            gout74 += (g2) * (2*beta*g50) * (g97) * weight0;
            gout75 += (g15) * (2*beta*g52) * weight0;
            gout76 += (D00x) * (2*beta*g80) * weight0;
            gout77 += (D00x) * (2*beta*g52) * (g97) * weight0;
            gout78 += (g15) * (2*beta*g50) * (D00z) * weight0;
            gout79 += (D00x) * (2*beta*g78) * (D00z) * weight0;
            gout80 += (D00x) * (2*beta*g50) * (g101) * weight0;
            gout81 += (g11) * (2*beta*g54) * weight0;
            gout82 += (2*beta*g85) * weight0;
            gout83 += (2*beta*g54) * (g97) * weight0;
            gout84 += (g11) * (2*beta*g52) * (D00z) * weight0;
            gout85 += (2*beta*g80) * (D00z) * weight0;
            gout86 += (2*beta*g52) * (g101) * weight0;
            gout87 += (g11) * (2*beta*g50) * (g88) * weight0;
            gout88 += (2*beta*g78) * (g88) * weight0;
            gout89 += (2*beta*g50) * (g112) * weight0;
            gout90 += (g26) * (2*beta*g92) * weight0;
            gout91 += (g2) * (g55) * (2*beta*g92) * weight0;
            gout92 += (g2) * (2*beta*g120) * weight0;
            gout93 += (g15) * (D00y) * (2*beta*g92) * weight0;
            gout94 += (D00x) * (g59) * (2*beta*g92) * weight0;
            gout95 += (D00x) * (D00y) * (2*beta*g120) * weight0;
            gout96 += (g15) * (2*beta*g94) * weight0;
            gout97 += (D00x) * (g55) * (2*beta*g94) * weight0;
            gout98 += (D00x) * (2*beta*g122) * weight0;
            gout99 += (g11) * (g46) * (2*beta*g92) * weight0;
            gout100 += (g70) * (2*beta*g92) * weight0;
            gout101 += (g46) * (2*beta*g120) * weight0;
            gout102 += (g11) * (D00y) * (2*beta*g94) * weight0;
            gout103 += (g59) * (2*beta*g94) * weight0;
            gout104 += (D00y) * (2*beta*g122) * weight0;
            gout105 += (g11) * (2*beta*g96) * weight0;
            gout106 += (g55) * (2*beta*g96) * weight0;
            gout107 += (2*beta*g127) * weight0;
        }
    } }

    int *ao_loc = c_bpcache.ao_loc;
    int i0 = ao_loc[ish];
    int j0 = ao_loc[jsh];
    int k0 = ao_loc[ksh];
    int l0 = ao_loc[lsh];
    int n_dm = jk.n_dm;
    int nao = jk.nao;
    size_t nao2 = nao * nao;
    double* __restrict__ dm = jk.dm;
    double *vj = jk.vj;
    double *vk = jk.vk;
    double d_0, d_1, d_2, d_3, d_4, d_5, d_6, d_7, d_8, d_9, d_10, d_11, d_12, d_13, d_14, d_15, d_16, d_17;

    for (int i_dm = 0; i_dm < n_dm; ++i_dm) {
        if (vj != NULL) {
            d_0 = dm[(k0+0)+nao*(l0+0)];
            d_1 = dm[(k0+0)+nao*(l0+1)];
            d_2 = dm[(k0+0)+nao*(l0+2)];
            d_3 = dm[(k0+1)+nao*(l0+0)];
            d_4 = dm[(k0+1)+nao*(l0+1)];
            d_5 = dm[(k0+1)+nao*(l0+2)];
            d_6 = dm[(k0+2)+nao*(l0+0)];
            d_7 = dm[(k0+2)+nao*(l0+1)];
            d_8 = dm[(k0+2)+nao*(l0+2)];
            d_9 = dm[(k0+3)+nao*(l0+0)];
            d_10 = dm[(k0+3)+nao*(l0+1)];
            d_11 = dm[(k0+3)+nao*(l0+2)];
            d_12 = dm[(k0+4)+nao*(l0+0)];
            d_13 = dm[(k0+4)+nao*(l0+1)];
            d_14 = dm[(k0+4)+nao*(l0+2)];
            d_15 = dm[(k0+5)+nao*(l0+0)];
            d_16 = dm[(k0+5)+nao*(l0+1)];
            d_17 = dm[(k0+5)+nao*(l0+2)];
            atomicAdd(vj+(i0+0)+nao*(j0+0), gout0*d_0+gout1*d_1+gout2*d_2+gout3*d_3+gout4*d_4+gout5*d_5+gout6*d_6+gout7*d_7+gout8*d_8+gout9*d_9+gout10*d_10+gout11*d_11+gout12*d_12+gout13*d_13+gout14*d_14+gout15*d_15+gout16*d_16+gout17*d_17);
            atomicAdd(vj+(i0+0)+nao*(j0+0)+nao2, gout18*d_0+gout19*d_1+gout20*d_2+gout21*d_3+gout22*d_4+gout23*d_5+gout24*d_6+gout25*d_7+gout26*d_8+gout27*d_9+gout28*d_10+gout29*d_11+gout30*d_12+gout31*d_13+gout32*d_14+gout33*d_15+gout34*d_16+gout35*d_17);
            atomicAdd(vj+(i0+0)+nao*(j0+0)+2*nao2, gout36*d_0+gout37*d_1+gout38*d_2+gout39*d_3+gout40*d_4+gout41*d_5+gout42*d_6+gout43*d_7+gout44*d_8+gout45*d_9+gout46*d_10+gout47*d_11+gout48*d_12+gout49*d_13+gout50*d_14+gout51*d_15+gout52*d_16+gout53*d_17);
            atomicAdd(vj+nao*(i0+0)+(j0+0), gout54*d_0+gout55*d_1+gout56*d_2+gout57*d_3+gout58*d_4+gout59*d_5+gout60*d_6+gout61*d_7+gout62*d_8+gout63*d_9+gout64*d_10+gout65*d_11+gout66*d_12+gout67*d_13+gout68*d_14+gout69*d_15+gout70*d_16+gout71*d_17);
            atomicAdd(vj+nao*(i0+0)+(j0+0)+nao2, gout72*d_0+gout73*d_1+gout74*d_2+gout75*d_3+gout76*d_4+gout77*d_5+gout78*d_6+gout79*d_7+gout80*d_8+gout81*d_9+gout82*d_10+gout83*d_11+gout84*d_12+gout85*d_13+gout86*d_14+gout87*d_15+gout88*d_16+gout89*d_17);
            atomicAdd(vj+nao*(i0+0)+(j0+0)+2*nao2, gout90*d_0+gout91*d_1+gout92*d_2+gout93*d_3+gout94*d_4+gout95*d_5+gout96*d_6+gout97*d_7+gout98*d_8+gout99*d_9+gout100*d_10+gout101*d_11+gout102*d_12+gout103*d_13+gout104*d_14+gout105*d_15+gout106*d_16+gout107*d_17);
            vj += 3*nao2;
        }
        if (vk != NULL) {
            // ijkl, jk -> il
            d_0 = dm[(j0+0)+nao*(k0+0)];
            d_1 = dm[(j0+0)+nao*(k0+1)];
            d_2 = dm[(j0+0)+nao*(k0+2)];
            d_3 = dm[(j0+0)+nao*(k0+3)];
            d_4 = dm[(j0+0)+nao*(k0+4)];
            d_5 = dm[(j0+0)+nao*(k0+5)];
            atomicAdd(vk+(i0+0)+nao*(l0+0), gout0*d_0+gout3*d_1+gout6*d_2+gout9*d_3+gout12*d_4+gout15*d_5);
            atomicAdd(vk+(i0+0)+nao*(l0+1), gout1*d_0+gout4*d_1+gout7*d_2+gout10*d_3+gout13*d_4+gout16*d_5);
            atomicAdd(vk+(i0+0)+nao*(l0+2), gout2*d_0+gout5*d_1+gout8*d_2+gout11*d_3+gout14*d_4+gout17*d_5);
            atomicAdd(vk+(i0+0)+nao*(l0+0)+nao2, gout18*d_0+gout21*d_1+gout24*d_2+gout27*d_3+gout30*d_4+gout33*d_5);
            atomicAdd(vk+(i0+0)+nao*(l0+1)+nao2, gout19*d_0+gout22*d_1+gout25*d_2+gout28*d_3+gout31*d_4+gout34*d_5);
            atomicAdd(vk+(i0+0)+nao*(l0+2)+nao2, gout20*d_0+gout23*d_1+gout26*d_2+gout29*d_3+gout32*d_4+gout35*d_5);
            atomicAdd(vk+(i0+0)+nao*(l0+0)+2*nao2, gout36*d_0+gout39*d_1+gout42*d_2+gout45*d_3+gout48*d_4+gout51*d_5);
            atomicAdd(vk+(i0+0)+nao*(l0+1)+2*nao2, gout37*d_0+gout40*d_1+gout43*d_2+gout46*d_3+gout49*d_4+gout52*d_5);
            atomicAdd(vk+(i0+0)+nao*(l0+2)+2*nao2, gout38*d_0+gout41*d_1+gout44*d_2+gout47*d_3+gout50*d_4+gout53*d_5);
            // ijkl, jl -> ik
            d_0 = dm[(j0+0)+nao*(l0+0)];
            d_1 = dm[(j0+0)+nao*(l0+1)];
            d_2 = dm[(j0+0)+nao*(l0+2)];
            atomicAdd(vk+(i0+0)+nao*(k0+0), gout0*d_0+gout1*d_1+gout2*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+1), gout3*d_0+gout4*d_1+gout5*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+2), gout6*d_0+gout7*d_1+gout8*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+3), gout9*d_0+gout10*d_1+gout11*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+4), gout12*d_0+gout13*d_1+gout14*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+5), gout15*d_0+gout16*d_1+gout17*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+0)+nao2, gout18*d_0+gout19*d_1+gout20*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+1)+nao2, gout21*d_0+gout22*d_1+gout23*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+2)+nao2, gout24*d_0+gout25*d_1+gout26*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+3)+nao2, gout27*d_0+gout28*d_1+gout29*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+4)+nao2, gout30*d_0+gout31*d_1+gout32*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+5)+nao2, gout33*d_0+gout34*d_1+gout35*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+0)+2*nao2, gout36*d_0+gout37*d_1+gout38*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+1)+2*nao2, gout39*d_0+gout40*d_1+gout41*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+2)+2*nao2, gout42*d_0+gout43*d_1+gout44*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+3)+2*nao2, gout45*d_0+gout46*d_1+gout47*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+4)+2*nao2, gout48*d_0+gout49*d_1+gout50*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+5)+2*nao2, gout51*d_0+gout52*d_1+gout53*d_2);
            // ijkl, ik -> jl
            d_0 = dm[(i0+0)+nao*(k0+0)];
            d_1 = dm[(i0+0)+nao*(k0+1)];
            d_2 = dm[(i0+0)+nao*(k0+2)];
            d_3 = dm[(i0+0)+nao*(k0+3)];
            d_4 = dm[(i0+0)+nao*(k0+4)];
            d_5 = dm[(i0+0)+nao*(k0+5)];
            atomicAdd(vk+(j0+0)+nao*(l0+0), gout54*d_0+gout57*d_1+gout60*d_2+gout63*d_3+gout66*d_4+gout69*d_5);
            atomicAdd(vk+(j0+0)+nao*(l0+1), gout55*d_0+gout58*d_1+gout61*d_2+gout64*d_3+gout67*d_4+gout70*d_5);
            atomicAdd(vk+(j0+0)+nao*(l0+2), gout56*d_0+gout59*d_1+gout62*d_2+gout65*d_3+gout68*d_4+gout71*d_5);
            atomicAdd(vk+(j0+0)+nao*(l0+0)+nao2, gout72*d_0+gout75*d_1+gout78*d_2+gout81*d_3+gout84*d_4+gout87*d_5);
            atomicAdd(vk+(j0+0)+nao*(l0+1)+nao2, gout73*d_0+gout76*d_1+gout79*d_2+gout82*d_3+gout85*d_4+gout88*d_5);
            atomicAdd(vk+(j0+0)+nao*(l0+2)+nao2, gout74*d_0+gout77*d_1+gout80*d_2+gout83*d_3+gout86*d_4+gout89*d_5);
            atomicAdd(vk+(j0+0)+nao*(l0+0)+2*nao2, gout90*d_0+gout93*d_1+gout96*d_2+gout99*d_3+gout102*d_4+gout105*d_5);
            atomicAdd(vk+(j0+0)+nao*(l0+1)+2*nao2, gout91*d_0+gout94*d_1+gout97*d_2+gout100*d_3+gout103*d_4+gout106*d_5);
            atomicAdd(vk+(j0+0)+nao*(l0+2)+2*nao2, gout92*d_0+gout95*d_1+gout98*d_2+gout101*d_3+gout104*d_4+gout107*d_5);
            // ijkl, il -> jk
            d_0 = dm[(i0+0)+nao*(l0+0)];
            d_1 = dm[(i0+0)+nao*(l0+1)];
            d_2 = dm[(i0+0)+nao*(l0+2)];
            atomicAdd(vk+(j0+0)+nao*(k0+0), gout54*d_0+gout55*d_1+gout56*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+1), gout57*d_0+gout58*d_1+gout59*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+2), gout60*d_0+gout61*d_1+gout62*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+3), gout63*d_0+gout64*d_1+gout65*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+4), gout66*d_0+gout67*d_1+gout68*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+5), gout69*d_0+gout70*d_1+gout71*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+0)+nao2, gout72*d_0+gout73*d_1+gout74*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+1)+nao2, gout75*d_0+gout76*d_1+gout77*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+2)+nao2, gout78*d_0+gout79*d_1+gout80*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+3)+nao2, gout81*d_0+gout82*d_1+gout83*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+4)+nao2, gout84*d_0+gout85*d_1+gout86*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+5)+nao2, gout87*d_0+gout88*d_1+gout89*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+0)+2*nao2, gout90*d_0+gout91*d_1+gout92*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+1)+2*nao2, gout93*d_0+gout94*d_1+gout95*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+2)+2*nao2, gout96*d_0+gout97*d_1+gout98*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+3)+2*nao2, gout99*d_0+gout100*d_1+gout101*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+4)+2*nao2, gout102*d_0+gout103*d_1+gout104*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+5)+2*nao2, gout105*d_0+gout106*d_1+gout107*d_2);
            vk += 3*nao2;
        }
        dm += nao2;
    }
}

__global__
static void GINTint2e_ip1_jk_kernel_0022(GINTEnvVars envs, JKMatrix jk,
                                    BasisProdOffsets offsets)
{
    int ntasks_ij = offsets.ntasks_ij;
    int ntasks_kl = offsets.ntasks_kl;
    int task_ij = blockIdx.x * blockDim.x + threadIdx.x;
    int task_kl = blockIdx.y * blockDim.y + threadIdx.y;
    if (task_ij >= ntasks_ij || task_kl >= ntasks_kl) {
        return;
    }
    int bas_ij = offsets.bas_ij + task_ij;
    int bas_kl = offsets.bas_kl + task_kl;
    double norm = envs.fac;
    double omega = envs.omega;
    int *bas_pair2bra = c_bpcache.bas_pair2bra;
    int *bas_pair2ket = c_bpcache.bas_pair2ket;
    int ish = bas_pair2bra[bas_ij];
    int jsh = bas_pair2ket[bas_ij];
    int ksh = bas_pair2bra[bas_kl];
    int lsh = bas_pair2ket[bas_kl];
    int nprim_ij = envs.nprim_ij;
    int nprim_kl = envs.nprim_kl;
    int prim_ij = offsets.primitive_ij + task_ij * nprim_ij;
    int prim_kl = offsets.primitive_kl + task_kl * nprim_kl;

    double* __restrict__ a12 = c_bpcache.a12;
    double* __restrict__ e12 = c_bpcache.e12;
    double* __restrict__ x12 = c_bpcache.x12;
    double* __restrict__ y12 = c_bpcache.y12;
    double* __restrict__ z12 = c_bpcache.z12;
    double * __restrict__ i_exponent = c_bpcache.a1;
    double * __restrict__ j_exponent = c_bpcache.a2;

    int ij, kl;
    int prim_ij0, prim_ij1, prim_kl0, prim_kl1;
    int nbas = c_bpcache.nbas;
    double* __restrict__ bas_x = c_bpcache.bas_coords;
    double* __restrict__ bas_y = bas_x + nbas;
    double* __restrict__ bas_z = bas_y + nbas;

    double gout0 = 0;
    double gout1 = 0;
    double gout2 = 0;
    double gout3 = 0;
    double gout4 = 0;
    double gout5 = 0;
    double gout6 = 0;
    double gout7 = 0;
    double gout8 = 0;
    double gout9 = 0;
    double gout10 = 0;
    double gout11 = 0;
    double gout12 = 0;
    double gout13 = 0;
    double gout14 = 0;
    double gout15 = 0;
    double gout16 = 0;
    double gout17 = 0;
    double gout18 = 0;
    double gout19 = 0;
    double gout20 = 0;
    double gout21 = 0;
    double gout22 = 0;
    double gout23 = 0;
    double gout24 = 0;
    double gout25 = 0;
    double gout26 = 0;
    double gout27 = 0;
    double gout28 = 0;
    double gout29 = 0;
    double gout30 = 0;
    double gout31 = 0;
    double gout32 = 0;
    double gout33 = 0;
    double gout34 = 0;
    double gout35 = 0;
    double gout36 = 0;
    double gout37 = 0;
    double gout38 = 0;
    double gout39 = 0;
    double gout40 = 0;
    double gout41 = 0;
    double gout42 = 0;
    double gout43 = 0;
    double gout44 = 0;
    double gout45 = 0;
    double gout46 = 0;
    double gout47 = 0;
    double gout48 = 0;
    double gout49 = 0;
    double gout50 = 0;
    double gout51 = 0;
    double gout52 = 0;
    double gout53 = 0;
    double gout54 = 0;
    double gout55 = 0;
    double gout56 = 0;
    double gout57 = 0;
    double gout58 = 0;
    double gout59 = 0;
    double gout60 = 0;
    double gout61 = 0;
    double gout62 = 0;
    double gout63 = 0;
    double gout64 = 0;
    double gout65 = 0;
    double gout66 = 0;
    double gout67 = 0;
    double gout68 = 0;
    double gout69 = 0;
    double gout70 = 0;
    double gout71 = 0;
    double gout72 = 0;
    double gout73 = 0;
    double gout74 = 0;
    double gout75 = 0;
    double gout76 = 0;
    double gout77 = 0;
    double gout78 = 0;
    double gout79 = 0;
    double gout80 = 0;
    double gout81 = 0;
    double gout82 = 0;
    double gout83 = 0;
    double gout84 = 0;
    double gout85 = 0;
    double gout86 = 0;
    double gout87 = 0;
    double gout88 = 0;
    double gout89 = 0;
    double gout90 = 0;
    double gout91 = 0;
    double gout92 = 0;
    double gout93 = 0;
    double gout94 = 0;
    double gout95 = 0;
    double gout96 = 0;
    double gout97 = 0;
    double gout98 = 0;
    double gout99 = 0;
    double gout100 = 0;
    double gout101 = 0;
    double gout102 = 0;
    double gout103 = 0;
    double gout104 = 0;
    double gout105 = 0;
    double gout106 = 0;
    double gout107 = 0;
    double gout108 = 0;
    double gout109 = 0;
    double gout110 = 0;
    double gout111 = 0;
    double gout112 = 0;
    double gout113 = 0;
    double gout114 = 0;
    double gout115 = 0;
    double gout116 = 0;
    double gout117 = 0;
    double gout118 = 0;
    double gout119 = 0;
    double gout120 = 0;
    double gout121 = 0;
    double gout122 = 0;
    double gout123 = 0;
    double gout124 = 0;
    double gout125 = 0;
    double gout126 = 0;
    double gout127 = 0;
    double gout128 = 0;
    double gout129 = 0;
    double gout130 = 0;
    double gout131 = 0;
    double gout132 = 0;
    double gout133 = 0;
    double gout134 = 0;
    double gout135 = 0;
    double gout136 = 0;
    double gout137 = 0;
    double gout138 = 0;
    double gout139 = 0;
    double gout140 = 0;
    double gout141 = 0;
    double gout142 = 0;
    double gout143 = 0;
    double gout144 = 0;
    double gout145 = 0;
    double gout146 = 0;
    double gout147 = 0;
    double gout148 = 0;
    double gout149 = 0;
    double gout150 = 0;
    double gout151 = 0;
    double gout152 = 0;
    double gout153 = 0;
    double gout154 = 0;
    double gout155 = 0;
    double gout156 = 0;
    double gout157 = 0;
    double gout158 = 0;
    double gout159 = 0;
    double gout160 = 0;
    double gout161 = 0;
    double gout162 = 0;
    double gout163 = 0;
    double gout164 = 0;
    double gout165 = 0;
    double gout166 = 0;
    double gout167 = 0;
    double gout168 = 0;
    double gout169 = 0;
    double gout170 = 0;
    double gout171 = 0;
    double gout172 = 0;
    double gout173 = 0;
    double gout174 = 0;
    double gout175 = 0;
    double gout176 = 0;
    double gout177 = 0;
    double gout178 = 0;
    double gout179 = 0;
    double gout180 = 0;
    double gout181 = 0;
    double gout182 = 0;
    double gout183 = 0;
    double gout184 = 0;
    double gout185 = 0;
    double gout186 = 0;
    double gout187 = 0;
    double gout188 = 0;
    double gout189 = 0;
    double gout190 = 0;
    double gout191 = 0;
    double gout192 = 0;
    double gout193 = 0;
    double gout194 = 0;
    double gout195 = 0;
    double gout196 = 0;
    double gout197 = 0;
    double gout198 = 0;
    double gout199 = 0;
    double gout200 = 0;
    double gout201 = 0;
    double gout202 = 0;
    double gout203 = 0;
    double gout204 = 0;
    double gout205 = 0;
    double gout206 = 0;
    double gout207 = 0;
    double gout208 = 0;
    double gout209 = 0;
    double gout210 = 0;
    double gout211 = 0;
    double gout212 = 0;
    double gout213 = 0;
    double gout214 = 0;
    double gout215 = 0;

    double xi = bas_x[ish];
    double yi = bas_y[ish];
    double zi = bas_z[ish];
    double ABx = xi - bas_x[jsh];
    double ABy = yi - bas_y[jsh];
    double ABz = zi - bas_z[jsh];
    double xk = bas_x[ksh];
    double yk = bas_y[ksh];
    double zk = bas_z[ksh];
    double CDx = xk - bas_x[lsh];
    double CDy = yk - bas_y[lsh];
    double CDz = zk - bas_z[lsh];
    prim_ij0 = prim_ij;
    prim_ij1 = prim_ij + nprim_ij;
    prim_kl0 = prim_kl;
    prim_kl1 = prim_kl + nprim_kl;
    double rw[6];
    int irys;
    for (ij = prim_ij0; ij < prim_ij1; ++ij) {
        double alpha = i_exponent[ij];
        double beta = j_exponent[ij];
        double aij = a12[ij];
        double eij = e12[ij];
        double xij = x12[ij];
        double yij = y12[ij];
        double zij = z12[ij];
    for (kl = prim_kl0; kl < prim_kl1; ++kl) {
        double akl = a12[kl];
        double ekl = e12[kl];
        double xkl = x12[kl];
        double ykl = y12[kl];
        double zkl = z12[kl];
        double xijxkl = xij - xkl;
        double yijykl = yij - ykl;
        double zijzkl = zij - zkl;
        double aijkl = aij + akl;
        double a1 = aij * akl;
        double a0 = a1 / aijkl;
        double theta = omega > 0.0 ? omega * omega / (omega * omega + a0) : 1.0; 
        a0 *= theta;
        double x = a0 * (xijxkl * xijxkl + yijykl * yijykl + zijzkl * zijzkl);
        double fac = norm * eij * ekl * sqrt(a0 / (a1 * a1 * a1));
        //double fac = norm * eij * ekl / (sqrt(aijkl) * a1);

        GINTrys_root<3>(x, rw);
        GINTscale_u<3>(rw, theta);
      for (irys = 0; irys < 3; ++irys) {
            double weight0 = rw[irys+3] * fac;
            double root0 = rw[irys];
            double u2 = a0 * root0;
            double tmp4 = .5 / (u2 * aijkl + a1);
            double B00 = u2 * tmp4;
            double tmp1 = 2 * B00;

            double tmp2 = tmp1 * akl;
            double C00x = xij - xi - tmp2 * xijxkl;
            double C00y = yij - yi - tmp2 * yijykl;
            double C00z = zij - zi - tmp2 * zijzkl;
            double B01 = B00 + tmp4 * aij;
            double tmp3 = tmp1 * aij;
            double D00x = xkl - xk + tmp3 * xijxkl;
            double D00y = ykl - yk + tmp3 * yijykl;
            double D00z = zkl - zk + tmp3 * zijzkl;

            double g1 = B00+(C00x*D00x);
            double g2 = B01+D00x*D00x;
            double g3 = 2*B00*D00x;
            double g4 = C00x*g2;
            double g5 = g3+g4;
            double g6 = ABx+C00x;
            double g7 = g6*D00x;
            double g8 = B00+g7;
            double g9 = g6*g2;
            double g10 = g3+g9;
            double g11 = CDx+D00x;
            double g12 = C00x*g11;
            double g13 = B00+g12;
            double g14 = D00x*g11;
            double g15 = B01+g14;
            double g16 = B01*C00x;
            double g17 = C00x*D00x*g11;
            double g18 = 2*D00x;
            double g19 = CDx+g18;
            double g20 = B00*g19;
            double g21 = g16+g17+g20;
            double g22 = D00x*D00x*g11;
            double g23 = 3*D00x;
            double g24 = CDx+g23;
            double g26 = g22+(B01*g24);
            double g27 = 3*B00*B01;
            double g31 = (2*CDx)+g23;
            double g33 = g27+(C00x*D00x*D00x*g11)+(B01*C00x*g24)+(B00*D00x*g31);
            double g35 = B00+(g6*g11);
            double g37 = g20+(g6*g15);
            double g39 = 3*B01;
            double g43 = (g6*g26)+(B00*(g39+(D00x*g31)));
            double g44 = B01+g11*g11;
            double g45 = 2*B00*g11;
            double g47 = g45+(C00x*g44);
            double g50 = (D00x*g11*g11)+(B01*g31);
            double g54 = g27+(C00x*D00x*g11*g11)+(B00*g11*g24)+(B01*C00x*g31);
            double g55 = 3*B01*B01;
            double g59 = CDx*CDx+(6*CDx*D00x)+(6*D00x*D00x);
            double g61 = g55+(D00x*D00x*g11*g11)+(B01*g59);
            double g62 = 3*B01*B01*C00x;
            double g65 = D00x*g11*(g17+(2*B00*g19));
            double g69 = B01*((6*B00*g19)+(C00x*g59));
            double g70 = g62+g65+g69;
            double g72 = g45+(g6*g44);
            double g77 = (B00*(g39+(g11*g24)))+(g6*g50);
            double g79 = g62+g65+(ABx*g61)+g69;
            double g81 = B00+(C00y*D00y);
            double g82 = B01+D00y*D00y;
            double g83 = 2*B00*D00y;
            double g85 = g83+(C00y*g82);
            double g86 = ABy+C00y;
            double g88 = B00+(g86*D00y);
            double g90 = g83+(g86*g82);
            double g91 = CDy+D00y;
            double g93 = B00+(C00y*g91);
            double g95 = B01+(D00y*g91);
            double g97 = C00y*D00y*g91;
            double g99 = CDy+(2*D00y);
            double g100 = B00*g99;
            double g101 = (B01*C00y)+g97+g100;
            double g103 = 3*D00y;
            double g104 = CDy+g103;
            double g106 = (D00y*D00y*g91)+(B01*g104);
            double g110 = (2*CDy)+g103;
            double g112 = g27+(C00y*D00y*D00y*g91)+(B01*C00y*g104)+(B00*D00y*g110);
            double g114 = B00+(g86*g91);
            double g116 = g100+(g86*g95);
            double g121 = (g86*g106)+(B00*(g39+(D00y*g110)));
            double g122 = B01+g91*g91;
            double g123 = 2*B00*g91;
            double g125 = g123+(C00y*g122);
            double g128 = (D00y*g91*g91)+(B01*g110);
            double g132 = g27+(C00y*D00y*g91*g91)+(B00*g91*g104)+(B01*C00y*g110);
            double g136 = CDy*CDy+(6*CDy*D00y)+(6*D00y*D00y);
            double g138 = g55+(D00y*D00y*g91*g91)+(B01*g136);
            double g139 = 3*B01*B01*C00y;
            double g142 = D00y*g91*(g97+(2*B00*g99));
            double g146 = B01*((6*B00*g99)+(C00y*g136));
            double g147 = g139+g142+g146;
            double g149 = g123+(g86*g122);
            double g154 = (B00*(g39+(g91*g104)))+(g86*g128);
            double g156 = g139+g142+(ABy*g138)+g146;
            double g158 = B00+(C00z*D00z);
            double g159 = B01+D00z*D00z;
            double g160 = 2*B00*D00z;
            double g162 = g160+(C00z*g159);
            double g163 = ABz+C00z;
            double g165 = B00+(g163*D00z);
            double g167 = g160+(g163*g159);
            double g168 = CDz+D00z;
            double g170 = B00+(C00z*g168);
            double g172 = B01+(D00z*g168);
            double g174 = C00z*D00z*g168;
            double g176 = CDz+(2*D00z);
            double g177 = B00*g176;
            double g178 = (B01*C00z)+g174+g177;
            double g180 = 3*D00z;
            double g181 = CDz+g180;
            double g183 = (D00z*D00z*g168)+(B01*g181);
            double g187 = (2*CDz)+g180;
            double g189 = g27+(C00z*D00z*D00z*g168)+(B01*C00z*g181)+(B00*D00z*g187);
            double g191 = B00+(g163*g168);
            double g193 = g177+(g163*g172);
            double g198 = (g163*g183)+(B00*(g39+(D00z*g187)));
            double g199 = B01+g168*g168;
            double g200 = 2*B00*g168;
            double g202 = g200+(C00z*g199);
            double g205 = (D00z*g168*g168)+(B01*g187);
            double g209 = g27+(C00z*D00z*g168*g168)+(B00*g168*g181)+(B01*C00z*g187);
            double g213 = CDz*CDz+(6*CDz*D00z)+(6*D00z*D00z);
            double g215 = g55+(D00z*D00z*g168*g168)+(B01*g213);
            double g216 = 3*B01*B01*C00z;
            double g219 = D00z*g168*(g174+(2*B00*g176));
            double g223 = B01*((6*B00*g176)+(C00z*g213));
            double g224 = g216+g219+g223;
            double g226 = g200+(g163*g199);
            double g231 = (B00*(g39+(g168*g181)))+(g163*g205);
            double g233 = g216+g219+(ABz*g215)+g223;

            gout0 += (2*alpha*g70) * weight0;
            gout1 += (2*alpha*g33) * (g91) * weight0;
            gout2 += (2*alpha*g33) * (g168) * weight0;
            gout3 += (2*alpha*g5) * (g122) * weight0;
            gout4 += (2*alpha*g5) * (g91) * (g168) * weight0;
            gout5 += (2*alpha*g5) * (g199) * weight0;
            gout6 += (2*alpha*g54) * (D00y) * weight0;
            gout7 += (2*alpha*g21) * (g95) * weight0;
            gout8 += (2*alpha*g21) * (D00y) * (g168) * weight0;
            gout9 += (2*alpha*g1) * (g128) * weight0;
            gout10 += (2*alpha*g1) * (g95) * (g168) * weight0;
            gout11 += (2*alpha*g1) * (D00y) * (g199) * weight0;
            gout12 += (2*alpha*g54) * (D00z) * weight0;
            gout13 += (2*alpha*g21) * (g91) * (D00z) * weight0;
            gout14 += (2*alpha*g21) * (g172) * weight0;
            gout15 += (2*alpha*g1) * (g122) * (D00z) * weight0;
            gout16 += (2*alpha*g1) * (g91) * (g172) * weight0;
            gout17 += (2*alpha*g1) * (g205) * weight0;
            gout18 += (2*alpha*g47) * (g82) * weight0;
            gout19 += (2*alpha*g13) * (g106) * weight0;
            gout20 += (2*alpha*g13) * (g82) * (g168) * weight0;
            gout21 += (2*alpha*C00x) * (g138) * weight0;
            gout22 += (2*alpha*C00x) * (g106) * (g168) * weight0;
            gout23 += (2*alpha*C00x) * (g82) * (g199) * weight0;
            gout24 += (2*alpha*g47) * (D00y) * (D00z) * weight0;
            gout25 += (2*alpha*g13) * (g95) * (D00z) * weight0;
            gout26 += (2*alpha*g13) * (D00y) * (g172) * weight0;
            gout27 += (2*alpha*C00x) * (g128) * (D00z) * weight0;
            gout28 += (2*alpha*C00x) * (g95) * (g172) * weight0;
            gout29 += (2*alpha*C00x) * (D00y) * (g205) * weight0;
            gout30 += (2*alpha*g47) * (g159) * weight0;
            gout31 += (2*alpha*g13) * (g91) * (g159) * weight0;
            gout32 += (2*alpha*g13) * (g183) * weight0;
            gout33 += (2*alpha*C00x) * (g122) * (g159) * weight0;
            gout34 += (2*alpha*C00x) * (g91) * (g183) * weight0;
            gout35 += (2*alpha*C00x) * (g215) * weight0;
            gout36 += (g61) * (2*alpha*C00y) * weight0;
            gout37 += (g26) * (2*alpha*g93) * weight0;
            gout38 += (g26) * (2*alpha*C00y) * (g168) * weight0;
            gout39 += (g2) * (2*alpha*g125) * weight0;
            gout40 += (g2) * (2*alpha*g93) * (g168) * weight0;
            gout41 += (g2) * (2*alpha*C00y) * (g199) * weight0;
            gout42 += (g50) * (2*alpha*g81) * weight0;
            gout43 += (g15) * (2*alpha*g101) * weight0;
            gout44 += (g15) * (2*alpha*g81) * (g168) * weight0;
            gout45 += (D00x) * (2*alpha*g132) * weight0;
            gout46 += (D00x) * (2*alpha*g101) * (g168) * weight0;
            gout47 += (D00x) * (2*alpha*g81) * (g199) * weight0;
            gout48 += (g50) * (2*alpha*C00y) * (D00z) * weight0;
            gout49 += (g15) * (2*alpha*g93) * (D00z) * weight0;
            gout50 += (g15) * (2*alpha*C00y) * (g172) * weight0;
            gout51 += (D00x) * (2*alpha*g125) * (D00z) * weight0;
            gout52 += (D00x) * (2*alpha*g93) * (g172) * weight0;
            gout53 += (D00x) * (2*alpha*C00y) * (g205) * weight0;
            gout54 += (g44) * (2*alpha*g85) * weight0;
            gout55 += (g11) * (2*alpha*g112) * weight0;
            gout56 += (g11) * (2*alpha*g85) * (g168) * weight0;
            gout57 += (2*alpha*g147) * weight0;
            gout58 += (2*alpha*g112) * (g168) * weight0;
            gout59 += (2*alpha*g85) * (g199) * weight0;
            gout60 += (g44) * (2*alpha*g81) * (D00z) * weight0;
            gout61 += (g11) * (2*alpha*g101) * (D00z) * weight0;
            gout62 += (g11) * (2*alpha*g81) * (g172) * weight0;
            gout63 += (2*alpha*g132) * (D00z) * weight0;
            gout64 += (2*alpha*g101) * (g172) * weight0;
            gout65 += (2*alpha*g81) * (g205) * weight0;
            gout66 += (g44) * (2*alpha*C00y) * (g159) * weight0;
            gout67 += (g11) * (2*alpha*g93) * (g159) * weight0;
            gout68 += (g11) * (2*alpha*C00y) * (g183) * weight0;
            gout69 += (2*alpha*g125) * (g159) * weight0;
            gout70 += (2*alpha*g93) * (g183) * weight0;
            gout71 += (2*alpha*C00y) * (g215) * weight0;
            gout72 += (g61) * (2*alpha*C00z) * weight0;
            gout73 += (g26) * (g91) * (2*alpha*C00z) * weight0;
            gout74 += (g26) * (2*alpha*g170) * weight0;
            gout75 += (g2) * (g122) * (2*alpha*C00z) * weight0;
            gout76 += (g2) * (g91) * (2*alpha*g170) * weight0;
            gout77 += (g2) * (2*alpha*g202) * weight0;
            gout78 += (g50) * (D00y) * (2*alpha*C00z) * weight0;
            gout79 += (g15) * (g95) * (2*alpha*C00z) * weight0;
            gout80 += (g15) * (D00y) * (2*alpha*g170) * weight0;
            gout81 += (D00x) * (g128) * (2*alpha*C00z) * weight0;
            gout82 += (D00x) * (g95) * (2*alpha*g170) * weight0;
            gout83 += (D00x) * (D00y) * (2*alpha*g202) * weight0;
            gout84 += (g50) * (2*alpha*g158) * weight0;
            gout85 += (g15) * (g91) * (2*alpha*g158) * weight0;
            gout86 += (g15) * (2*alpha*g178) * weight0;
            gout87 += (D00x) * (g122) * (2*alpha*g158) * weight0;
            gout88 += (D00x) * (g91) * (2*alpha*g178) * weight0;
            gout89 += (D00x) * (2*alpha*g209) * weight0;
            gout90 += (g44) * (g82) * (2*alpha*C00z) * weight0;
            gout91 += (g11) * (g106) * (2*alpha*C00z) * weight0;
            gout92 += (g11) * (g82) * (2*alpha*g170) * weight0;
            gout93 += (g138) * (2*alpha*C00z) * weight0;
            gout94 += (g106) * (2*alpha*g170) * weight0;
            gout95 += (g82) * (2*alpha*g202) * weight0;
            gout96 += (g44) * (D00y) * (2*alpha*g158) * weight0;
            gout97 += (g11) * (g95) * (2*alpha*g158) * weight0;
            gout98 += (g11) * (D00y) * (2*alpha*g178) * weight0;
            gout99 += (g128) * (2*alpha*g158) * weight0;
            gout100 += (g95) * (2*alpha*g178) * weight0;
            gout101 += (D00y) * (2*alpha*g209) * weight0;
            gout102 += (g44) * (2*alpha*g162) * weight0;
            gout103 += (g11) * (g91) * (2*alpha*g162) * weight0;
            gout104 += (g11) * (2*alpha*g189) * weight0;
            gout105 += (g122) * (2*alpha*g162) * weight0;
            gout106 += (g91) * (2*alpha*g189) * weight0;
            gout107 += (2*alpha*g224) * weight0;
            gout108 += (2*beta*g79) * weight0;
            gout109 += (2*beta*g43) * (g91) * weight0;
            gout110 += (2*beta*g43) * (g168) * weight0;
            gout111 += (2*beta*g10) * (g122) * weight0;
            gout112 += (2*beta*g10) * (g91) * (g168) * weight0;
            gout113 += (2*beta*g10) * (g199) * weight0;
            gout114 += (2*beta*g77) * (D00y) * weight0;
            gout115 += (2*beta*g37) * (g95) * weight0;
            gout116 += (2*beta*g37) * (D00y) * (g168) * weight0;
            gout117 += (2*beta*g8) * (g128) * weight0;
            gout118 += (2*beta*g8) * (g95) * (g168) * weight0;
            gout119 += (2*beta*g8) * (D00y) * (g199) * weight0;
            gout120 += (2*beta*g77) * (D00z) * weight0;
            gout121 += (2*beta*g37) * (g91) * (D00z) * weight0;
            gout122 += (2*beta*g37) * (g172) * weight0;
            gout123 += (2*beta*g8) * (g122) * (D00z) * weight0;
            gout124 += (2*beta*g8) * (g91) * (g172) * weight0;
            gout125 += (2*beta*g8) * (g205) * weight0;
            gout126 += (2*beta*g72) * (g82) * weight0;
            gout127 += (2*beta*g35) * (g106) * weight0;
            gout128 += (2*beta*g35) * (g82) * (g168) * weight0;
            gout129 += (2*beta*g6) * (g138) * weight0;
            gout130 += (2*beta*g6) * (g106) * (g168) * weight0;
            gout131 += (2*beta*g6) * (g82) * (g199) * weight0;
            gout132 += (2*beta*g72) * (D00y) * (D00z) * weight0;
            gout133 += (2*beta*g35) * (g95) * (D00z) * weight0;
            gout134 += (2*beta*g35) * (D00y) * (g172) * weight0;
            gout135 += (2*beta*g6) * (g128) * (D00z) * weight0;
            gout136 += (2*beta*g6) * (g95) * (g172) * weight0;
            gout137 += (2*beta*g6) * (D00y) * (g205) * weight0;
            gout138 += (2*beta*g72) * (g159) * weight0;
            gout139 += (2*beta*g35) * (g91) * (g159) * weight0;
            gout140 += (2*beta*g35) * (g183) * weight0;
            gout141 += (2*beta*g6) * (g122) * (g159) * weight0;
            gout142 += (2*beta*g6) * (g91) * (g183) * weight0;
            gout143 += (2*beta*g6) * (g215) * weight0;
            gout144 += (g61) * (2*beta*g86) * weight0;
            gout145 += (g26) * (2*beta*g114) * weight0;
            gout146 += (g26) * (2*beta*g86) * (g168) * weight0;
            gout147 += (g2) * (2*beta*g149) * weight0;
            gout148 += (g2) * (2*beta*g114) * (g168) * weight0;
            gout149 += (g2) * (2*beta*g86) * (g199) * weight0;
            gout150 += (g50) * (2*beta*g88) * weight0;
            gout151 += (g15) * (2*beta*g116) * weight0;
            gout152 += (g15) * (2*beta*g88) * (g168) * weight0;
            gout153 += (D00x) * (2*beta*g154) * weight0;
            gout154 += (D00x) * (2*beta*g116) * (g168) * weight0;
            gout155 += (D00x) * (2*beta*g88) * (g199) * weight0;
            gout156 += (g50) * (2*beta*g86) * (D00z) * weight0;
            gout157 += (g15) * (2*beta*g114) * (D00z) * weight0;
            gout158 += (g15) * (2*beta*g86) * (g172) * weight0;
            gout159 += (D00x) * (2*beta*g149) * (D00z) * weight0;
            gout160 += (D00x) * (2*beta*g114) * (g172) * weight0;
            gout161 += (D00x) * (2*beta*g86) * (g205) * weight0;
            gout162 += (g44) * (2*beta*g90) * weight0;
            gout163 += (g11) * (2*beta*g121) * weight0;
            gout164 += (g11) * (2*beta*g90) * (g168) * weight0;
            gout165 += (2*beta*g156) * weight0;
            gout166 += (2*beta*g121) * (g168) * weight0;
            gout167 += (2*beta*g90) * (g199) * weight0;
            gout168 += (g44) * (2*beta*g88) * (D00z) * weight0;
            gout169 += (g11) * (2*beta*g116) * (D00z) * weight0;
            gout170 += (g11) * (2*beta*g88) * (g172) * weight0;
            gout171 += (2*beta*g154) * (D00z) * weight0;
            gout172 += (2*beta*g116) * (g172) * weight0;
            gout173 += (2*beta*g88) * (g205) * weight0;
            gout174 += (g44) * (2*beta*g86) * (g159) * weight0;
            gout175 += (g11) * (2*beta*g114) * (g159) * weight0;
            gout176 += (g11) * (2*beta*g86) * (g183) * weight0;
            gout177 += (2*beta*g149) * (g159) * weight0;
            gout178 += (2*beta*g114) * (g183) * weight0;
            gout179 += (2*beta*g86) * (g215) * weight0;
            gout180 += (g61) * (2*beta*g163) * weight0;
            gout181 += (g26) * (g91) * (2*beta*g163) * weight0;
            gout182 += (g26) * (2*beta*g191) * weight0;
            gout183 += (g2) * (g122) * (2*beta*g163) * weight0;
            gout184 += (g2) * (g91) * (2*beta*g191) * weight0;
            gout185 += (g2) * (2*beta*g226) * weight0;
            gout186 += (g50) * (D00y) * (2*beta*g163) * weight0;
            gout187 += (g15) * (g95) * (2*beta*g163) * weight0;
            gout188 += (g15) * (D00y) * (2*beta*g191) * weight0;
            gout189 += (D00x) * (g128) * (2*beta*g163) * weight0;
            gout190 += (D00x) * (g95) * (2*beta*g191) * weight0;
            gout191 += (D00x) * (D00y) * (2*beta*g226) * weight0;
            gout192 += (g50) * (2*beta*g165) * weight0;
            gout193 += (g15) * (g91) * (2*beta*g165) * weight0;
            gout194 += (g15) * (2*beta*g193) * weight0;
            gout195 += (D00x) * (g122) * (2*beta*g165) * weight0;
            gout196 += (D00x) * (g91) * (2*beta*g193) * weight0;
            gout197 += (D00x) * (2*beta*g231) * weight0;
            gout198 += (g44) * (g82) * (2*beta*g163) * weight0;
            gout199 += (g11) * (g106) * (2*beta*g163) * weight0;
            gout200 += (g11) * (g82) * (2*beta*g191) * weight0;
            gout201 += (g138) * (2*beta*g163) * weight0;
            gout202 += (g106) * (2*beta*g191) * weight0;
            gout203 += (g82) * (2*beta*g226) * weight0;
            gout204 += (g44) * (D00y) * (2*beta*g165) * weight0;
            gout205 += (g11) * (g95) * (2*beta*g165) * weight0;
            gout206 += (g11) * (D00y) * (2*beta*g193) * weight0;
            gout207 += (g128) * (2*beta*g165) * weight0;
            gout208 += (g95) * (2*beta*g193) * weight0;
            gout209 += (D00y) * (2*beta*g231) * weight0;
            gout210 += (g44) * (2*beta*g167) * weight0;
            gout211 += (g11) * (g91) * (2*beta*g167) * weight0;
            gout212 += (g11) * (2*beta*g198) * weight0;
            gout213 += (g122) * (2*beta*g167) * weight0;
            gout214 += (g91) * (2*beta*g198) * weight0;
            gout215 += (2*beta*g233) * weight0;
        }
    } }

    int *ao_loc = c_bpcache.ao_loc;
    int i0 = ao_loc[ish];
    int j0 = ao_loc[jsh];
    int k0 = ao_loc[ksh];
    int l0 = ao_loc[lsh];
    int n_dm = jk.n_dm;
    int nao = jk.nao;
    size_t nao2 = nao * nao;
    double* __restrict__ dm = jk.dm;
    double *vj = jk.vj;
    double *vk = jk.vk;
    double d_0, d_1, d_2, d_3, d_4, d_5, d_6, d_7, d_8, d_9, d_10, d_11, d_12, d_13, d_14, d_15, d_16, d_17, d_18, d_19, d_20, d_21, d_22, d_23, d_24, d_25, d_26, d_27, d_28, d_29, d_30, d_31, d_32, d_33, d_34, d_35;

    for (int i_dm = 0; i_dm < n_dm; ++i_dm) {
        if (vj != NULL) {
            d_0 = dm[(k0+0)+nao*(l0+0)];
            d_1 = dm[(k0+0)+nao*(l0+1)];
            d_2 = dm[(k0+0)+nao*(l0+2)];
            d_3 = dm[(k0+0)+nao*(l0+3)];
            d_4 = dm[(k0+0)+nao*(l0+4)];
            d_5 = dm[(k0+0)+nao*(l0+5)];
            d_6 = dm[(k0+1)+nao*(l0+0)];
            d_7 = dm[(k0+1)+nao*(l0+1)];
            d_8 = dm[(k0+1)+nao*(l0+2)];
            d_9 = dm[(k0+1)+nao*(l0+3)];
            d_10 = dm[(k0+1)+nao*(l0+4)];
            d_11 = dm[(k0+1)+nao*(l0+5)];
            d_12 = dm[(k0+2)+nao*(l0+0)];
            d_13 = dm[(k0+2)+nao*(l0+1)];
            d_14 = dm[(k0+2)+nao*(l0+2)];
            d_15 = dm[(k0+2)+nao*(l0+3)];
            d_16 = dm[(k0+2)+nao*(l0+4)];
            d_17 = dm[(k0+2)+nao*(l0+5)];
            d_18 = dm[(k0+3)+nao*(l0+0)];
            d_19 = dm[(k0+3)+nao*(l0+1)];
            d_20 = dm[(k0+3)+nao*(l0+2)];
            d_21 = dm[(k0+3)+nao*(l0+3)];
            d_22 = dm[(k0+3)+nao*(l0+4)];
            d_23 = dm[(k0+3)+nao*(l0+5)];
            d_24 = dm[(k0+4)+nao*(l0+0)];
            d_25 = dm[(k0+4)+nao*(l0+1)];
            d_26 = dm[(k0+4)+nao*(l0+2)];
            d_27 = dm[(k0+4)+nao*(l0+3)];
            d_28 = dm[(k0+4)+nao*(l0+4)];
            d_29 = dm[(k0+4)+nao*(l0+5)];
            d_30 = dm[(k0+5)+nao*(l0+0)];
            d_31 = dm[(k0+5)+nao*(l0+1)];
            d_32 = dm[(k0+5)+nao*(l0+2)];
            d_33 = dm[(k0+5)+nao*(l0+3)];
            d_34 = dm[(k0+5)+nao*(l0+4)];
            d_35 = dm[(k0+5)+nao*(l0+5)];
            atomicAdd(vj+(i0+0)+nao*(j0+0), gout0*d_0+gout1*d_1+gout2*d_2+gout3*d_3+gout4*d_4+gout5*d_5+gout6*d_6+gout7*d_7+gout8*d_8+gout9*d_9+gout10*d_10+gout11*d_11+gout12*d_12+gout13*d_13+gout14*d_14+gout15*d_15+gout16*d_16+gout17*d_17+gout18*d_18+gout19*d_19+gout20*d_20+gout21*d_21+gout22*d_22+gout23*d_23+gout24*d_24+gout25*d_25+gout26*d_26+gout27*d_27+gout28*d_28+gout29*d_29+gout30*d_30+gout31*d_31+gout32*d_32+gout33*d_33+gout34*d_34+gout35*d_35);
            atomicAdd(vj+(i0+0)+nao*(j0+0)+nao2, gout36*d_0+gout37*d_1+gout38*d_2+gout39*d_3+gout40*d_4+gout41*d_5+gout42*d_6+gout43*d_7+gout44*d_8+gout45*d_9+gout46*d_10+gout47*d_11+gout48*d_12+gout49*d_13+gout50*d_14+gout51*d_15+gout52*d_16+gout53*d_17+gout54*d_18+gout55*d_19+gout56*d_20+gout57*d_21+gout58*d_22+gout59*d_23+gout60*d_24+gout61*d_25+gout62*d_26+gout63*d_27+gout64*d_28+gout65*d_29+gout66*d_30+gout67*d_31+gout68*d_32+gout69*d_33+gout70*d_34+gout71*d_35);
            atomicAdd(vj+(i0+0)+nao*(j0+0)+2*nao2, gout72*d_0+gout73*d_1+gout74*d_2+gout75*d_3+gout76*d_4+gout77*d_5+gout78*d_6+gout79*d_7+gout80*d_8+gout81*d_9+gout82*d_10+gout83*d_11+gout84*d_12+gout85*d_13+gout86*d_14+gout87*d_15+gout88*d_16+gout89*d_17+gout90*d_18+gout91*d_19+gout92*d_20+gout93*d_21+gout94*d_22+gout95*d_23+gout96*d_24+gout97*d_25+gout98*d_26+gout99*d_27+gout100*d_28+gout101*d_29+gout102*d_30+gout103*d_31+gout104*d_32+gout105*d_33+gout106*d_34+gout107*d_35);
            atomicAdd(vj+nao*(i0+0)+(j0+0), gout108*d_0+gout109*d_1+gout110*d_2+gout111*d_3+gout112*d_4+gout113*d_5+gout114*d_6+gout115*d_7+gout116*d_8+gout117*d_9+gout118*d_10+gout119*d_11+gout120*d_12+gout121*d_13+gout122*d_14+gout123*d_15+gout124*d_16+gout125*d_17+gout126*d_18+gout127*d_19+gout128*d_20+gout129*d_21+gout130*d_22+gout131*d_23+gout132*d_24+gout133*d_25+gout134*d_26+gout135*d_27+gout136*d_28+gout137*d_29+gout138*d_30+gout139*d_31+gout140*d_32+gout141*d_33+gout142*d_34+gout143*d_35);
            atomicAdd(vj+nao*(i0+0)+(j0+0)+nao2, gout144*d_0+gout145*d_1+gout146*d_2+gout147*d_3+gout148*d_4+gout149*d_5+gout150*d_6+gout151*d_7+gout152*d_8+gout153*d_9+gout154*d_10+gout155*d_11+gout156*d_12+gout157*d_13+gout158*d_14+gout159*d_15+gout160*d_16+gout161*d_17+gout162*d_18+gout163*d_19+gout164*d_20+gout165*d_21+gout166*d_22+gout167*d_23+gout168*d_24+gout169*d_25+gout170*d_26+gout171*d_27+gout172*d_28+gout173*d_29+gout174*d_30+gout175*d_31+gout176*d_32+gout177*d_33+gout178*d_34+gout179*d_35);
            atomicAdd(vj+nao*(i0+0)+(j0+0)+2*nao2, gout180*d_0+gout181*d_1+gout182*d_2+gout183*d_3+gout184*d_4+gout185*d_5+gout186*d_6+gout187*d_7+gout188*d_8+gout189*d_9+gout190*d_10+gout191*d_11+gout192*d_12+gout193*d_13+gout194*d_14+gout195*d_15+gout196*d_16+gout197*d_17+gout198*d_18+gout199*d_19+gout200*d_20+gout201*d_21+gout202*d_22+gout203*d_23+gout204*d_24+gout205*d_25+gout206*d_26+gout207*d_27+gout208*d_28+gout209*d_29+gout210*d_30+gout211*d_31+gout212*d_32+gout213*d_33+gout214*d_34+gout215*d_35);
            vj += 3*nao2;
        }
        if (vk != NULL) {
            // ijkl, jk -> il
            d_0 = dm[(j0+0)+nao*(k0+0)];
            d_1 = dm[(j0+0)+nao*(k0+1)];
            d_2 = dm[(j0+0)+nao*(k0+2)];
            d_3 = dm[(j0+0)+nao*(k0+3)];
            d_4 = dm[(j0+0)+nao*(k0+4)];
            d_5 = dm[(j0+0)+nao*(k0+5)];
            atomicAdd(vk+(i0+0)+nao*(l0+0), gout0*d_0+gout6*d_1+gout12*d_2+gout18*d_3+gout24*d_4+gout30*d_5);
            atomicAdd(vk+(i0+0)+nao*(l0+1), gout1*d_0+gout7*d_1+gout13*d_2+gout19*d_3+gout25*d_4+gout31*d_5);
            atomicAdd(vk+(i0+0)+nao*(l0+2), gout2*d_0+gout8*d_1+gout14*d_2+gout20*d_3+gout26*d_4+gout32*d_5);
            atomicAdd(vk+(i0+0)+nao*(l0+3), gout3*d_0+gout9*d_1+gout15*d_2+gout21*d_3+gout27*d_4+gout33*d_5);
            atomicAdd(vk+(i0+0)+nao*(l0+4), gout4*d_0+gout10*d_1+gout16*d_2+gout22*d_3+gout28*d_4+gout34*d_5);
            atomicAdd(vk+(i0+0)+nao*(l0+5), gout5*d_0+gout11*d_1+gout17*d_2+gout23*d_3+gout29*d_4+gout35*d_5);
            atomicAdd(vk+(i0+0)+nao*(l0+0)+nao2, gout36*d_0+gout42*d_1+gout48*d_2+gout54*d_3+gout60*d_4+gout66*d_5);
            atomicAdd(vk+(i0+0)+nao*(l0+1)+nao2, gout37*d_0+gout43*d_1+gout49*d_2+gout55*d_3+gout61*d_4+gout67*d_5);
            atomicAdd(vk+(i0+0)+nao*(l0+2)+nao2, gout38*d_0+gout44*d_1+gout50*d_2+gout56*d_3+gout62*d_4+gout68*d_5);
            atomicAdd(vk+(i0+0)+nao*(l0+3)+nao2, gout39*d_0+gout45*d_1+gout51*d_2+gout57*d_3+gout63*d_4+gout69*d_5);
            atomicAdd(vk+(i0+0)+nao*(l0+4)+nao2, gout40*d_0+gout46*d_1+gout52*d_2+gout58*d_3+gout64*d_4+gout70*d_5);
            atomicAdd(vk+(i0+0)+nao*(l0+5)+nao2, gout41*d_0+gout47*d_1+gout53*d_2+gout59*d_3+gout65*d_4+gout71*d_5);
            atomicAdd(vk+(i0+0)+nao*(l0+0)+2*nao2, gout72*d_0+gout78*d_1+gout84*d_2+gout90*d_3+gout96*d_4+gout102*d_5);
            atomicAdd(vk+(i0+0)+nao*(l0+1)+2*nao2, gout73*d_0+gout79*d_1+gout85*d_2+gout91*d_3+gout97*d_4+gout103*d_5);
            atomicAdd(vk+(i0+0)+nao*(l0+2)+2*nao2, gout74*d_0+gout80*d_1+gout86*d_2+gout92*d_3+gout98*d_4+gout104*d_5);
            atomicAdd(vk+(i0+0)+nao*(l0+3)+2*nao2, gout75*d_0+gout81*d_1+gout87*d_2+gout93*d_3+gout99*d_4+gout105*d_5);
            atomicAdd(vk+(i0+0)+nao*(l0+4)+2*nao2, gout76*d_0+gout82*d_1+gout88*d_2+gout94*d_3+gout100*d_4+gout106*d_5);
            atomicAdd(vk+(i0+0)+nao*(l0+5)+2*nao2, gout77*d_0+gout83*d_1+gout89*d_2+gout95*d_3+gout101*d_4+gout107*d_5);
            // ijkl, jl -> ik
            d_0 = dm[(j0+0)+nao*(l0+0)];
            d_1 = dm[(j0+0)+nao*(l0+1)];
            d_2 = dm[(j0+0)+nao*(l0+2)];
            d_3 = dm[(j0+0)+nao*(l0+3)];
            d_4 = dm[(j0+0)+nao*(l0+4)];
            d_5 = dm[(j0+0)+nao*(l0+5)];
            atomicAdd(vk+(i0+0)+nao*(k0+0), gout0*d_0+gout1*d_1+gout2*d_2+gout3*d_3+gout4*d_4+gout5*d_5);
            atomicAdd(vk+(i0+0)+nao*(k0+1), gout6*d_0+gout7*d_1+gout8*d_2+gout9*d_3+gout10*d_4+gout11*d_5);
            atomicAdd(vk+(i0+0)+nao*(k0+2), gout12*d_0+gout13*d_1+gout14*d_2+gout15*d_3+gout16*d_4+gout17*d_5);
            atomicAdd(vk+(i0+0)+nao*(k0+3), gout18*d_0+gout19*d_1+gout20*d_2+gout21*d_3+gout22*d_4+gout23*d_5);
            atomicAdd(vk+(i0+0)+nao*(k0+4), gout24*d_0+gout25*d_1+gout26*d_2+gout27*d_3+gout28*d_4+gout29*d_5);
            atomicAdd(vk+(i0+0)+nao*(k0+5), gout30*d_0+gout31*d_1+gout32*d_2+gout33*d_3+gout34*d_4+gout35*d_5);
            atomicAdd(vk+(i0+0)+nao*(k0+0)+nao2, gout36*d_0+gout37*d_1+gout38*d_2+gout39*d_3+gout40*d_4+gout41*d_5);
            atomicAdd(vk+(i0+0)+nao*(k0+1)+nao2, gout42*d_0+gout43*d_1+gout44*d_2+gout45*d_3+gout46*d_4+gout47*d_5);
            atomicAdd(vk+(i0+0)+nao*(k0+2)+nao2, gout48*d_0+gout49*d_1+gout50*d_2+gout51*d_3+gout52*d_4+gout53*d_5);
            atomicAdd(vk+(i0+0)+nao*(k0+3)+nao2, gout54*d_0+gout55*d_1+gout56*d_2+gout57*d_3+gout58*d_4+gout59*d_5);
            atomicAdd(vk+(i0+0)+nao*(k0+4)+nao2, gout60*d_0+gout61*d_1+gout62*d_2+gout63*d_3+gout64*d_4+gout65*d_5);
            atomicAdd(vk+(i0+0)+nao*(k0+5)+nao2, gout66*d_0+gout67*d_1+gout68*d_2+gout69*d_3+gout70*d_4+gout71*d_5);
            atomicAdd(vk+(i0+0)+nao*(k0+0)+2*nao2, gout72*d_0+gout73*d_1+gout74*d_2+gout75*d_3+gout76*d_4+gout77*d_5);
            atomicAdd(vk+(i0+0)+nao*(k0+1)+2*nao2, gout78*d_0+gout79*d_1+gout80*d_2+gout81*d_3+gout82*d_4+gout83*d_5);
            atomicAdd(vk+(i0+0)+nao*(k0+2)+2*nao2, gout84*d_0+gout85*d_1+gout86*d_2+gout87*d_3+gout88*d_4+gout89*d_5);
            atomicAdd(vk+(i0+0)+nao*(k0+3)+2*nao2, gout90*d_0+gout91*d_1+gout92*d_2+gout93*d_3+gout94*d_4+gout95*d_5);
            atomicAdd(vk+(i0+0)+nao*(k0+4)+2*nao2, gout96*d_0+gout97*d_1+gout98*d_2+gout99*d_3+gout100*d_4+gout101*d_5);
            atomicAdd(vk+(i0+0)+nao*(k0+5)+2*nao2, gout102*d_0+gout103*d_1+gout104*d_2+gout105*d_3+gout106*d_4+gout107*d_5);
            // ijkl, ik -> jl
            d_0 = dm[(i0+0)+nao*(k0+0)];
            d_1 = dm[(i0+0)+nao*(k0+1)];
            d_2 = dm[(i0+0)+nao*(k0+2)];
            d_3 = dm[(i0+0)+nao*(k0+3)];
            d_4 = dm[(i0+0)+nao*(k0+4)];
            d_5 = dm[(i0+0)+nao*(k0+5)];
            atomicAdd(vk+(j0+0)+nao*(l0+0), gout108*d_0+gout114*d_1+gout120*d_2+gout126*d_3+gout132*d_4+gout138*d_5);
            atomicAdd(vk+(j0+0)+nao*(l0+1), gout109*d_0+gout115*d_1+gout121*d_2+gout127*d_3+gout133*d_4+gout139*d_5);
            atomicAdd(vk+(j0+0)+nao*(l0+2), gout110*d_0+gout116*d_1+gout122*d_2+gout128*d_3+gout134*d_4+gout140*d_5);
            atomicAdd(vk+(j0+0)+nao*(l0+3), gout111*d_0+gout117*d_1+gout123*d_2+gout129*d_3+gout135*d_4+gout141*d_5);
            atomicAdd(vk+(j0+0)+nao*(l0+4), gout112*d_0+gout118*d_1+gout124*d_2+gout130*d_3+gout136*d_4+gout142*d_5);
            atomicAdd(vk+(j0+0)+nao*(l0+5), gout113*d_0+gout119*d_1+gout125*d_2+gout131*d_3+gout137*d_4+gout143*d_5);
            atomicAdd(vk+(j0+0)+nao*(l0+0)+nao2, gout144*d_0+gout150*d_1+gout156*d_2+gout162*d_3+gout168*d_4+gout174*d_5);
            atomicAdd(vk+(j0+0)+nao*(l0+1)+nao2, gout145*d_0+gout151*d_1+gout157*d_2+gout163*d_3+gout169*d_4+gout175*d_5);
            atomicAdd(vk+(j0+0)+nao*(l0+2)+nao2, gout146*d_0+gout152*d_1+gout158*d_2+gout164*d_3+gout170*d_4+gout176*d_5);
            atomicAdd(vk+(j0+0)+nao*(l0+3)+nao2, gout147*d_0+gout153*d_1+gout159*d_2+gout165*d_3+gout171*d_4+gout177*d_5);
            atomicAdd(vk+(j0+0)+nao*(l0+4)+nao2, gout148*d_0+gout154*d_1+gout160*d_2+gout166*d_3+gout172*d_4+gout178*d_5);
            atomicAdd(vk+(j0+0)+nao*(l0+5)+nao2, gout149*d_0+gout155*d_1+gout161*d_2+gout167*d_3+gout173*d_4+gout179*d_5);
            atomicAdd(vk+(j0+0)+nao*(l0+0)+2*nao2, gout180*d_0+gout186*d_1+gout192*d_2+gout198*d_3+gout204*d_4+gout210*d_5);
            atomicAdd(vk+(j0+0)+nao*(l0+1)+2*nao2, gout181*d_0+gout187*d_1+gout193*d_2+gout199*d_3+gout205*d_4+gout211*d_5);
            atomicAdd(vk+(j0+0)+nao*(l0+2)+2*nao2, gout182*d_0+gout188*d_1+gout194*d_2+gout200*d_3+gout206*d_4+gout212*d_5);
            atomicAdd(vk+(j0+0)+nao*(l0+3)+2*nao2, gout183*d_0+gout189*d_1+gout195*d_2+gout201*d_3+gout207*d_4+gout213*d_5);
            atomicAdd(vk+(j0+0)+nao*(l0+4)+2*nao2, gout184*d_0+gout190*d_1+gout196*d_2+gout202*d_3+gout208*d_4+gout214*d_5);
            atomicAdd(vk+(j0+0)+nao*(l0+5)+2*nao2, gout185*d_0+gout191*d_1+gout197*d_2+gout203*d_3+gout209*d_4+gout215*d_5);
            // ijkl, il -> jk
            d_0 = dm[(i0+0)+nao*(l0+0)];
            d_1 = dm[(i0+0)+nao*(l0+1)];
            d_2 = dm[(i0+0)+nao*(l0+2)];
            d_3 = dm[(i0+0)+nao*(l0+3)];
            d_4 = dm[(i0+0)+nao*(l0+4)];
            d_5 = dm[(i0+0)+nao*(l0+5)];
            atomicAdd(vk+(j0+0)+nao*(k0+0), gout108*d_0+gout109*d_1+gout110*d_2+gout111*d_3+gout112*d_4+gout113*d_5);
            atomicAdd(vk+(j0+0)+nao*(k0+1), gout114*d_0+gout115*d_1+gout116*d_2+gout117*d_3+gout118*d_4+gout119*d_5);
            atomicAdd(vk+(j0+0)+nao*(k0+2), gout120*d_0+gout121*d_1+gout122*d_2+gout123*d_3+gout124*d_4+gout125*d_5);
            atomicAdd(vk+(j0+0)+nao*(k0+3), gout126*d_0+gout127*d_1+gout128*d_2+gout129*d_3+gout130*d_4+gout131*d_5);
            atomicAdd(vk+(j0+0)+nao*(k0+4), gout132*d_0+gout133*d_1+gout134*d_2+gout135*d_3+gout136*d_4+gout137*d_5);
            atomicAdd(vk+(j0+0)+nao*(k0+5), gout138*d_0+gout139*d_1+gout140*d_2+gout141*d_3+gout142*d_4+gout143*d_5);
            atomicAdd(vk+(j0+0)+nao*(k0+0)+nao2, gout144*d_0+gout145*d_1+gout146*d_2+gout147*d_3+gout148*d_4+gout149*d_5);
            atomicAdd(vk+(j0+0)+nao*(k0+1)+nao2, gout150*d_0+gout151*d_1+gout152*d_2+gout153*d_3+gout154*d_4+gout155*d_5);
            atomicAdd(vk+(j0+0)+nao*(k0+2)+nao2, gout156*d_0+gout157*d_1+gout158*d_2+gout159*d_3+gout160*d_4+gout161*d_5);
            atomicAdd(vk+(j0+0)+nao*(k0+3)+nao2, gout162*d_0+gout163*d_1+gout164*d_2+gout165*d_3+gout166*d_4+gout167*d_5);
            atomicAdd(vk+(j0+0)+nao*(k0+4)+nao2, gout168*d_0+gout169*d_1+gout170*d_2+gout171*d_3+gout172*d_4+gout173*d_5);
            atomicAdd(vk+(j0+0)+nao*(k0+5)+nao2, gout174*d_0+gout175*d_1+gout176*d_2+gout177*d_3+gout178*d_4+gout179*d_5);
            atomicAdd(vk+(j0+0)+nao*(k0+0)+2*nao2, gout180*d_0+gout181*d_1+gout182*d_2+gout183*d_3+gout184*d_4+gout185*d_5);
            atomicAdd(vk+(j0+0)+nao*(k0+1)+2*nao2, gout186*d_0+gout187*d_1+gout188*d_2+gout189*d_3+gout190*d_4+gout191*d_5);
            atomicAdd(vk+(j0+0)+nao*(k0+2)+2*nao2, gout192*d_0+gout193*d_1+gout194*d_2+gout195*d_3+gout196*d_4+gout197*d_5);
            atomicAdd(vk+(j0+0)+nao*(k0+3)+2*nao2, gout198*d_0+gout199*d_1+gout200*d_2+gout201*d_3+gout202*d_4+gout203*d_5);
            atomicAdd(vk+(j0+0)+nao*(k0+4)+2*nao2, gout204*d_0+gout205*d_1+gout206*d_2+gout207*d_3+gout208*d_4+gout209*d_5);
            atomicAdd(vk+(j0+0)+nao*(k0+5)+2*nao2, gout210*d_0+gout211*d_1+gout212*d_2+gout213*d_3+gout214*d_4+gout215*d_5);
            vk += 3*nao2;
        }
        dm += nao2;
    }
}

__global__
static void GINTint2e_ip1_jk_kernel_0030(GINTEnvVars envs, JKMatrix jk,
                                    BasisProdOffsets offsets)
{
    int ntasks_ij = offsets.ntasks_ij;
    int ntasks_kl = offsets.ntasks_kl;
    int task_ij = blockIdx.x * blockDim.x + threadIdx.x;
    int task_kl = blockIdx.y * blockDim.y + threadIdx.y;
    if (task_ij >= ntasks_ij || task_kl >= ntasks_kl) {
        return;
    }
    int bas_ij = offsets.bas_ij + task_ij;
    int bas_kl = offsets.bas_kl + task_kl;
    double norm = envs.fac;
    double omega = envs.omega;
    int *bas_pair2bra = c_bpcache.bas_pair2bra;
    int *bas_pair2ket = c_bpcache.bas_pair2ket;
    int ish = bas_pair2bra[bas_ij];
    int jsh = bas_pair2ket[bas_ij];
    int ksh = bas_pair2bra[bas_kl];
    int lsh = bas_pair2ket[bas_kl];
    int nprim_ij = envs.nprim_ij;
    int nprim_kl = envs.nprim_kl;
    int prim_ij = offsets.primitive_ij + task_ij * nprim_ij;
    int prim_kl = offsets.primitive_kl + task_kl * nprim_kl;

    double* __restrict__ a12 = c_bpcache.a12;
    double* __restrict__ e12 = c_bpcache.e12;
    double* __restrict__ x12 = c_bpcache.x12;
    double* __restrict__ y12 = c_bpcache.y12;
    double* __restrict__ z12 = c_bpcache.z12;
    double * __restrict__ i_exponent = c_bpcache.a1;
    double * __restrict__ j_exponent = c_bpcache.a2;

    int ij, kl;
    int prim_ij0, prim_ij1, prim_kl0, prim_kl1;
    int nbas = c_bpcache.nbas;
    double* __restrict__ bas_x = c_bpcache.bas_coords;
    double* __restrict__ bas_y = bas_x + nbas;
    double* __restrict__ bas_z = bas_y + nbas;

    double gout0 = 0;
    double gout1 = 0;
    double gout2 = 0;
    double gout3 = 0;
    double gout4 = 0;
    double gout5 = 0;
    double gout6 = 0;
    double gout7 = 0;
    double gout8 = 0;
    double gout9 = 0;
    double gout10 = 0;
    double gout11 = 0;
    double gout12 = 0;
    double gout13 = 0;
    double gout14 = 0;
    double gout15 = 0;
    double gout16 = 0;
    double gout17 = 0;
    double gout18 = 0;
    double gout19 = 0;
    double gout20 = 0;
    double gout21 = 0;
    double gout22 = 0;
    double gout23 = 0;
    double gout24 = 0;
    double gout25 = 0;
    double gout26 = 0;
    double gout27 = 0;
    double gout28 = 0;
    double gout29 = 0;
    double gout30 = 0;
    double gout31 = 0;
    double gout32 = 0;
    double gout33 = 0;
    double gout34 = 0;
    double gout35 = 0;
    double gout36 = 0;
    double gout37 = 0;
    double gout38 = 0;
    double gout39 = 0;
    double gout40 = 0;
    double gout41 = 0;
    double gout42 = 0;
    double gout43 = 0;
    double gout44 = 0;
    double gout45 = 0;
    double gout46 = 0;
    double gout47 = 0;
    double gout48 = 0;
    double gout49 = 0;
    double gout50 = 0;
    double gout51 = 0;
    double gout52 = 0;
    double gout53 = 0;
    double gout54 = 0;
    double gout55 = 0;
    double gout56 = 0;
    double gout57 = 0;
    double gout58 = 0;
    double gout59 = 0;

    double xi = bas_x[ish];
    double yi = bas_y[ish];
    double zi = bas_z[ish];
    double ABx = xi - bas_x[jsh];
    double ABy = yi - bas_y[jsh];
    double ABz = zi - bas_z[jsh];
    double xk = bas_x[ksh];
    double yk = bas_y[ksh];
    double zk = bas_z[ksh];

    prim_ij0 = prim_ij;
    prim_ij1 = prim_ij + nprim_ij;
    prim_kl0 = prim_kl;
    prim_kl1 = prim_kl + nprim_kl;
    double rw[6];
    int irys;
    for (ij = prim_ij0; ij < prim_ij1; ++ij) {
        double alpha = i_exponent[ij];
        double beta = j_exponent[ij];
        double aij = a12[ij];
        double eij = e12[ij];
        double xij = x12[ij];
        double yij = y12[ij];
        double zij = z12[ij];
    for (kl = prim_kl0; kl < prim_kl1; ++kl) {
        double akl = a12[kl];
        double ekl = e12[kl];
        double xkl = x12[kl];
        double ykl = y12[kl];
        double zkl = z12[kl];
        double xijxkl = xij - xkl;
        double yijykl = yij - ykl;
        double zijzkl = zij - zkl;
        double aijkl = aij + akl;
        double a1 = aij * akl;
        double a0 = a1 / aijkl;
        double theta = omega > 0.0 ? omega * omega / (omega * omega + a0) : 1.0; 
        a0 *= theta;
        double x = a0 * (xijxkl * xijxkl + yijykl * yijykl + zijzkl * zijzkl);
        double fac = norm * eij * ekl * sqrt(a0 / (a1 * a1 * a1));
        //double fac = norm * eij * ekl / (sqrt(aijkl) * a1);

        GINTrys_root<3>(x, rw);
        GINTscale_u<3>(rw, theta);
      for (irys = 0; irys < 3; ++irys) {
            double weight0 = rw[irys+3] * fac;
            double root0 = rw[irys];
            double u2 = a0 * root0;
            double tmp4 = .5 / (u2 * aijkl + a1);
            double B00 = u2 * tmp4;
            double tmp1 = 2 * B00;

            double tmp2 = tmp1 * akl;
            double C00x = xij - xi - tmp2 * xijxkl;
            double C00y = yij - yi - tmp2 * yijykl;
            double C00z = zij - zi - tmp2 * zijzkl;
            double B01 = B00 + tmp4 * aij;
            double tmp3 = tmp1 * aij;
            double D00x = xkl - xk + tmp3 * xijxkl;
            double D00y = ykl - yk + tmp3 * yijykl;
            double D00z = zkl - zk + tmp3 * zijzkl;

            double g1 = B00+(C00x*D00x);
            double g2 = B01+D00x*D00x;
            double g3 = 2*B00*D00x;
            double g4 = C00x*g2;
            double g5 = g3+g4;
            double g7 = (3*B01*D00x)+D00x*D00x*D00x;
            double g8 = 3*B00*g2;
            double g9 = 3*B01;
            double g10 = g9+D00x*D00x;
            double g12 = g8+(C00x*D00x*g10);
            double g13 = ABx+C00x;
            double g15 = B00+(g13*D00x);
            double g17 = g3+(g13*g2);
            double g19 = g8+(g13*D00x*g10);
            double g21 = B00+(C00y*D00y);
            double g22 = B01+D00y*D00y;
            double g23 = 2*B00*D00y;
            double g25 = g23+(C00y*g22);
            double g27 = (3*B01*D00y)+D00y*D00y*D00y;
            double g28 = 3*B00*g22;
            double g29 = g9+D00y*D00y;
            double g31 = g28+(C00y*D00y*g29);
            double g32 = ABy+C00y;
            double g34 = B00+(g32*D00y);
            double g36 = g23+(g32*g22);
            double g38 = g28+(g32*D00y*g29);
            double g40 = B00+(C00z*D00z);
            double g41 = B01+D00z*D00z;
            double g42 = 2*B00*D00z;
            double g44 = g42+(C00z*g41);
            double g46 = (3*B01*D00z)+D00z*D00z*D00z;
            double g47 = 3*B00*g41;
            double g48 = g9+D00z*D00z;
            double g50 = g47+(C00z*D00z*g48);
            double g51 = ABz+C00z;
            double g53 = B00+(g51*D00z);
            double g55 = g42+(g51*g41);
            double g57 = g47+(g51*D00z*g48);

            gout0 += (2*alpha*g12) * weight0;
            gout1 += (2*alpha*g5) * (D00y) * weight0;
            gout2 += (2*alpha*g5) * (D00z) * weight0;
            gout3 += (2*alpha*g1) * (g22) * weight0;
            gout4 += (2*alpha*g1) * (D00y) * (D00z) * weight0;
            gout5 += (2*alpha*g1) * (g41) * weight0;
            gout6 += (2*alpha*C00x) * (g27) * weight0;
            gout7 += (2*alpha*C00x) * (g22) * (D00z) * weight0;
            gout8 += (2*alpha*C00x) * (D00y) * (g41) * weight0;
            gout9 += (2*alpha*C00x) * (g46) * weight0;
            gout10 += (g7) * (2*alpha*C00y) * weight0;
            gout11 += (g2) * (2*alpha*g21) * weight0;
            gout12 += (g2) * (2*alpha*C00y) * (D00z) * weight0;
            gout13 += (D00x) * (2*alpha*g25) * weight0;
            gout14 += (D00x) * (2*alpha*g21) * (D00z) * weight0;
            gout15 += (D00x) * (2*alpha*C00y) * (g41) * weight0;
            gout16 += (2*alpha*g31) * weight0;
            gout17 += (2*alpha*g25) * (D00z) * weight0;
            gout18 += (2*alpha*g21) * (g41) * weight0;
            gout19 += (2*alpha*C00y) * (g46) * weight0;
            gout20 += (g7) * (2*alpha*C00z) * weight0;
            gout21 += (g2) * (D00y) * (2*alpha*C00z) * weight0;
            gout22 += (g2) * (2*alpha*g40) * weight0;
            gout23 += (D00x) * (g22) * (2*alpha*C00z) * weight0;
            gout24 += (D00x) * (D00y) * (2*alpha*g40) * weight0;
            gout25 += (D00x) * (2*alpha*g44) * weight0;
            gout26 += (g27) * (2*alpha*C00z) * weight0;
            gout27 += (g22) * (2*alpha*g40) * weight0;
            gout28 += (D00y) * (2*alpha*g44) * weight0;
            gout29 += (2*alpha*g50) * weight0;
            gout30 += (2*beta*g19) * weight0;
            gout31 += (2*beta*g17) * (D00y) * weight0;
            gout32 += (2*beta*g17) * (D00z) * weight0;
            gout33 += (2*beta*g15) * (g22) * weight0;
            gout34 += (2*beta*g15) * (D00y) * (D00z) * weight0;
            gout35 += (2*beta*g15) * (g41) * weight0;
            gout36 += (2*beta*g13) * (g27) * weight0;
            gout37 += (2*beta*g13) * (g22) * (D00z) * weight0;
            gout38 += (2*beta*g13) * (D00y) * (g41) * weight0;
            gout39 += (2*beta*g13) * (g46) * weight0;
            gout40 += (g7) * (2*beta*g32) * weight0;
            gout41 += (g2) * (2*beta*g34) * weight0;
            gout42 += (g2) * (2*beta*g32) * (D00z) * weight0;
            gout43 += (D00x) * (2*beta*g36) * weight0;
            gout44 += (D00x) * (2*beta*g34) * (D00z) * weight0;
            gout45 += (D00x) * (2*beta*g32) * (g41) * weight0;
            gout46 += (2*beta*g38) * weight0;
            gout47 += (2*beta*g36) * (D00z) * weight0;
            gout48 += (2*beta*g34) * (g41) * weight0;
            gout49 += (2*beta*g32) * (g46) * weight0;
            gout50 += (g7) * (2*beta*g51) * weight0;
            gout51 += (g2) * (D00y) * (2*beta*g51) * weight0;
            gout52 += (g2) * (2*beta*g53) * weight0;
            gout53 += (D00x) * (g22) * (2*beta*g51) * weight0;
            gout54 += (D00x) * (D00y) * (2*beta*g53) * weight0;
            gout55 += (D00x) * (2*beta*g55) * weight0;
            gout56 += (g27) * (2*beta*g51) * weight0;
            gout57 += (g22) * (2*beta*g53) * weight0;
            gout58 += (D00y) * (2*beta*g55) * weight0;
            gout59 += (2*beta*g57) * weight0;
        }
    } }

    int *ao_loc = c_bpcache.ao_loc;
    int i0 = ao_loc[ish];
    int j0 = ao_loc[jsh];
    int k0 = ao_loc[ksh];
    int l0 = ao_loc[lsh];
    int n_dm = jk.n_dm;
    int nao = jk.nao;
    size_t nao2 = nao * nao;
    double* __restrict__ dm = jk.dm;
    double *vj = jk.vj;
    double *vk = jk.vk;
    double d_0, d_1, d_2, d_3, d_4, d_5, d_6, d_7, d_8, d_9;

    for (int i_dm = 0; i_dm < n_dm; ++i_dm) {
        if (vj != NULL) {
            d_0 = dm[(k0+0)+nao*(l0+0)];
            d_1 = dm[(k0+1)+nao*(l0+0)];
            d_2 = dm[(k0+2)+nao*(l0+0)];
            d_3 = dm[(k0+3)+nao*(l0+0)];
            d_4 = dm[(k0+4)+nao*(l0+0)];
            d_5 = dm[(k0+5)+nao*(l0+0)];
            d_6 = dm[(k0+6)+nao*(l0+0)];
            d_7 = dm[(k0+7)+nao*(l0+0)];
            d_8 = dm[(k0+8)+nao*(l0+0)];
            d_9 = dm[(k0+9)+nao*(l0+0)];
            atomicAdd(vj+(i0+0)+nao*(j0+0), gout0*d_0+gout1*d_1+gout2*d_2+gout3*d_3+gout4*d_4+gout5*d_5+gout6*d_6+gout7*d_7+gout8*d_8+gout9*d_9);
            atomicAdd(vj+(i0+0)+nao*(j0+0)+nao2, gout10*d_0+gout11*d_1+gout12*d_2+gout13*d_3+gout14*d_4+gout15*d_5+gout16*d_6+gout17*d_7+gout18*d_8+gout19*d_9);
            atomicAdd(vj+(i0+0)+nao*(j0+0)+2*nao2, gout20*d_0+gout21*d_1+gout22*d_2+gout23*d_3+gout24*d_4+gout25*d_5+gout26*d_6+gout27*d_7+gout28*d_8+gout29*d_9);
            atomicAdd(vj+nao*(i0+0)+(j0+0), gout30*d_0+gout31*d_1+gout32*d_2+gout33*d_3+gout34*d_4+gout35*d_5+gout36*d_6+gout37*d_7+gout38*d_8+gout39*d_9);
            atomicAdd(vj+nao*(i0+0)+(j0+0)+nao2, gout40*d_0+gout41*d_1+gout42*d_2+gout43*d_3+gout44*d_4+gout45*d_5+gout46*d_6+gout47*d_7+gout48*d_8+gout49*d_9);
            atomicAdd(vj+nao*(i0+0)+(j0+0)+2*nao2, gout50*d_0+gout51*d_1+gout52*d_2+gout53*d_3+gout54*d_4+gout55*d_5+gout56*d_6+gout57*d_7+gout58*d_8+gout59*d_9);
            vj += 3*nao2;
        }
        if (vk != NULL) {
            // ijkl, jk -> il
            d_0 = dm[(j0+0)+nao*(k0+0)];
            d_1 = dm[(j0+0)+nao*(k0+1)];
            d_2 = dm[(j0+0)+nao*(k0+2)];
            d_3 = dm[(j0+0)+nao*(k0+3)];
            d_4 = dm[(j0+0)+nao*(k0+4)];
            d_5 = dm[(j0+0)+nao*(k0+5)];
            d_6 = dm[(j0+0)+nao*(k0+6)];
            d_7 = dm[(j0+0)+nao*(k0+7)];
            d_8 = dm[(j0+0)+nao*(k0+8)];
            d_9 = dm[(j0+0)+nao*(k0+9)];
            atomicAdd(vk+(i0+0)+nao*(l0+0), gout0*d_0+gout1*d_1+gout2*d_2+gout3*d_3+gout4*d_4+gout5*d_5+gout6*d_6+gout7*d_7+gout8*d_8+gout9*d_9);
            atomicAdd(vk+(i0+0)+nao*(l0+0)+nao2, gout10*d_0+gout11*d_1+gout12*d_2+gout13*d_3+gout14*d_4+gout15*d_5+gout16*d_6+gout17*d_7+gout18*d_8+gout19*d_9);
            atomicAdd(vk+(i0+0)+nao*(l0+0)+2*nao2, gout20*d_0+gout21*d_1+gout22*d_2+gout23*d_3+gout24*d_4+gout25*d_5+gout26*d_6+gout27*d_7+gout28*d_8+gout29*d_9);
            // ijkl, jl -> ik
            d_0 = dm[(j0+0)+nao*(l0+0)];
            atomicAdd(vk+(i0+0)+nao*(k0+0), gout0*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+1), gout1*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+2), gout2*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+3), gout3*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+4), gout4*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+5), gout5*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+6), gout6*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+7), gout7*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+8), gout8*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+9), gout9*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+0)+nao2, gout10*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+1)+nao2, gout11*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+2)+nao2, gout12*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+3)+nao2, gout13*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+4)+nao2, gout14*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+5)+nao2, gout15*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+6)+nao2, gout16*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+7)+nao2, gout17*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+8)+nao2, gout18*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+9)+nao2, gout19*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+0)+2*nao2, gout20*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+1)+2*nao2, gout21*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+2)+2*nao2, gout22*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+3)+2*nao2, gout23*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+4)+2*nao2, gout24*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+5)+2*nao2, gout25*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+6)+2*nao2, gout26*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+7)+2*nao2, gout27*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+8)+2*nao2, gout28*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+9)+2*nao2, gout29*d_0);
            // ijkl, ik -> jl
            d_0 = dm[(i0+0)+nao*(k0+0)];
            d_1 = dm[(i0+0)+nao*(k0+1)];
            d_2 = dm[(i0+0)+nao*(k0+2)];
            d_3 = dm[(i0+0)+nao*(k0+3)];
            d_4 = dm[(i0+0)+nao*(k0+4)];
            d_5 = dm[(i0+0)+nao*(k0+5)];
            d_6 = dm[(i0+0)+nao*(k0+6)];
            d_7 = dm[(i0+0)+nao*(k0+7)];
            d_8 = dm[(i0+0)+nao*(k0+8)];
            d_9 = dm[(i0+0)+nao*(k0+9)];
            atomicAdd(vk+(j0+0)+nao*(l0+0), gout30*d_0+gout31*d_1+gout32*d_2+gout33*d_3+gout34*d_4+gout35*d_5+gout36*d_6+gout37*d_7+gout38*d_8+gout39*d_9);
            atomicAdd(vk+(j0+0)+nao*(l0+0)+nao2, gout40*d_0+gout41*d_1+gout42*d_2+gout43*d_3+gout44*d_4+gout45*d_5+gout46*d_6+gout47*d_7+gout48*d_8+gout49*d_9);
            atomicAdd(vk+(j0+0)+nao*(l0+0)+2*nao2, gout50*d_0+gout51*d_1+gout52*d_2+gout53*d_3+gout54*d_4+gout55*d_5+gout56*d_6+gout57*d_7+gout58*d_8+gout59*d_9);
            // ijkl, il -> jk
            d_0 = dm[(i0+0)+nao*(l0+0)];
            atomicAdd(vk+(j0+0)+nao*(k0+0), gout30*d_0);
            atomicAdd(vk+(j0+0)+nao*(k0+1), gout31*d_0);
            atomicAdd(vk+(j0+0)+nao*(k0+2), gout32*d_0);
            atomicAdd(vk+(j0+0)+nao*(k0+3), gout33*d_0);
            atomicAdd(vk+(j0+0)+nao*(k0+4), gout34*d_0);
            atomicAdd(vk+(j0+0)+nao*(k0+5), gout35*d_0);
            atomicAdd(vk+(j0+0)+nao*(k0+6), gout36*d_0);
            atomicAdd(vk+(j0+0)+nao*(k0+7), gout37*d_0);
            atomicAdd(vk+(j0+0)+nao*(k0+8), gout38*d_0);
            atomicAdd(vk+(j0+0)+nao*(k0+9), gout39*d_0);
            atomicAdd(vk+(j0+0)+nao*(k0+0)+nao2, gout40*d_0);
            atomicAdd(vk+(j0+0)+nao*(k0+1)+nao2, gout41*d_0);
            atomicAdd(vk+(j0+0)+nao*(k0+2)+nao2, gout42*d_0);
            atomicAdd(vk+(j0+0)+nao*(k0+3)+nao2, gout43*d_0);
            atomicAdd(vk+(j0+0)+nao*(k0+4)+nao2, gout44*d_0);
            atomicAdd(vk+(j0+0)+nao*(k0+5)+nao2, gout45*d_0);
            atomicAdd(vk+(j0+0)+nao*(k0+6)+nao2, gout46*d_0);
            atomicAdd(vk+(j0+0)+nao*(k0+7)+nao2, gout47*d_0);
            atomicAdd(vk+(j0+0)+nao*(k0+8)+nao2, gout48*d_0);
            atomicAdd(vk+(j0+0)+nao*(k0+9)+nao2, gout49*d_0);
            atomicAdd(vk+(j0+0)+nao*(k0+0)+2*nao2, gout50*d_0);
            atomicAdd(vk+(j0+0)+nao*(k0+1)+2*nao2, gout51*d_0);
            atomicAdd(vk+(j0+0)+nao*(k0+2)+2*nao2, gout52*d_0);
            atomicAdd(vk+(j0+0)+nao*(k0+3)+2*nao2, gout53*d_0);
            atomicAdd(vk+(j0+0)+nao*(k0+4)+2*nao2, gout54*d_0);
            atomicAdd(vk+(j0+0)+nao*(k0+5)+2*nao2, gout55*d_0);
            atomicAdd(vk+(j0+0)+nao*(k0+6)+2*nao2, gout56*d_0);
            atomicAdd(vk+(j0+0)+nao*(k0+7)+2*nao2, gout57*d_0);
            atomicAdd(vk+(j0+0)+nao*(k0+8)+2*nao2, gout58*d_0);
            atomicAdd(vk+(j0+0)+nao*(k0+9)+2*nao2, gout59*d_0);
            vk += 3*nao2;
        }
        dm += nao2;
    }
}

__global__
static void GINTint2e_ip1_jk_kernel_0031(GINTEnvVars envs, JKMatrix jk,
                                    BasisProdOffsets offsets)
{
    int ntasks_ij = offsets.ntasks_ij;
    int ntasks_kl = offsets.ntasks_kl;
    int task_ij = blockIdx.x * blockDim.x + threadIdx.x;
    int task_kl = blockIdx.y * blockDim.y + threadIdx.y;
    if (task_ij >= ntasks_ij || task_kl >= ntasks_kl) {
        return;
    }
    int bas_ij = offsets.bas_ij + task_ij;
    int bas_kl = offsets.bas_kl + task_kl;
    double norm = envs.fac;
    double omega = envs.omega;
    int *bas_pair2bra = c_bpcache.bas_pair2bra;
    int *bas_pair2ket = c_bpcache.bas_pair2ket;
    int ish = bas_pair2bra[bas_ij];
    int jsh = bas_pair2ket[bas_ij];
    int ksh = bas_pair2bra[bas_kl];
    int lsh = bas_pair2ket[bas_kl];
    int nprim_ij = envs.nprim_ij;
    int nprim_kl = envs.nprim_kl;
    int prim_ij = offsets.primitive_ij + task_ij * nprim_ij;
    int prim_kl = offsets.primitive_kl + task_kl * nprim_kl;

    double* __restrict__ a12 = c_bpcache.a12;
    double* __restrict__ e12 = c_bpcache.e12;
    double* __restrict__ x12 = c_bpcache.x12;
    double* __restrict__ y12 = c_bpcache.y12;
    double* __restrict__ z12 = c_bpcache.z12;
    double * __restrict__ i_exponent = c_bpcache.a1;
    double * __restrict__ j_exponent = c_bpcache.a2;

    int ij, kl;
    int prim_ij0, prim_ij1, prim_kl0, prim_kl1;
    int nbas = c_bpcache.nbas;
    double* __restrict__ bas_x = c_bpcache.bas_coords;
    double* __restrict__ bas_y = bas_x + nbas;
    double* __restrict__ bas_z = bas_y + nbas;

    double gout0 = 0;
    double gout1 = 0;
    double gout2 = 0;
    double gout3 = 0;
    double gout4 = 0;
    double gout5 = 0;
    double gout6 = 0;
    double gout7 = 0;
    double gout8 = 0;
    double gout9 = 0;
    double gout10 = 0;
    double gout11 = 0;
    double gout12 = 0;
    double gout13 = 0;
    double gout14 = 0;
    double gout15 = 0;
    double gout16 = 0;
    double gout17 = 0;
    double gout18 = 0;
    double gout19 = 0;
    double gout20 = 0;
    double gout21 = 0;
    double gout22 = 0;
    double gout23 = 0;
    double gout24 = 0;
    double gout25 = 0;
    double gout26 = 0;
    double gout27 = 0;
    double gout28 = 0;
    double gout29 = 0;
    double gout30 = 0;
    double gout31 = 0;
    double gout32 = 0;
    double gout33 = 0;
    double gout34 = 0;
    double gout35 = 0;
    double gout36 = 0;
    double gout37 = 0;
    double gout38 = 0;
    double gout39 = 0;
    double gout40 = 0;
    double gout41 = 0;
    double gout42 = 0;
    double gout43 = 0;
    double gout44 = 0;
    double gout45 = 0;
    double gout46 = 0;
    double gout47 = 0;
    double gout48 = 0;
    double gout49 = 0;
    double gout50 = 0;
    double gout51 = 0;
    double gout52 = 0;
    double gout53 = 0;
    double gout54 = 0;
    double gout55 = 0;
    double gout56 = 0;
    double gout57 = 0;
    double gout58 = 0;
    double gout59 = 0;
    double gout60 = 0;
    double gout61 = 0;
    double gout62 = 0;
    double gout63 = 0;
    double gout64 = 0;
    double gout65 = 0;
    double gout66 = 0;
    double gout67 = 0;
    double gout68 = 0;
    double gout69 = 0;
    double gout70 = 0;
    double gout71 = 0;
    double gout72 = 0;
    double gout73 = 0;
    double gout74 = 0;
    double gout75 = 0;
    double gout76 = 0;
    double gout77 = 0;
    double gout78 = 0;
    double gout79 = 0;
    double gout80 = 0;
    double gout81 = 0;
    double gout82 = 0;
    double gout83 = 0;
    double gout84 = 0;
    double gout85 = 0;
    double gout86 = 0;
    double gout87 = 0;
    double gout88 = 0;
    double gout89 = 0;
    double gout90 = 0;
    double gout91 = 0;
    double gout92 = 0;
    double gout93 = 0;
    double gout94 = 0;
    double gout95 = 0;
    double gout96 = 0;
    double gout97 = 0;
    double gout98 = 0;
    double gout99 = 0;
    double gout100 = 0;
    double gout101 = 0;
    double gout102 = 0;
    double gout103 = 0;
    double gout104 = 0;
    double gout105 = 0;
    double gout106 = 0;
    double gout107 = 0;
    double gout108 = 0;
    double gout109 = 0;
    double gout110 = 0;
    double gout111 = 0;
    double gout112 = 0;
    double gout113 = 0;
    double gout114 = 0;
    double gout115 = 0;
    double gout116 = 0;
    double gout117 = 0;
    double gout118 = 0;
    double gout119 = 0;
    double gout120 = 0;
    double gout121 = 0;
    double gout122 = 0;
    double gout123 = 0;
    double gout124 = 0;
    double gout125 = 0;
    double gout126 = 0;
    double gout127 = 0;
    double gout128 = 0;
    double gout129 = 0;
    double gout130 = 0;
    double gout131 = 0;
    double gout132 = 0;
    double gout133 = 0;
    double gout134 = 0;
    double gout135 = 0;
    double gout136 = 0;
    double gout137 = 0;
    double gout138 = 0;
    double gout139 = 0;
    double gout140 = 0;
    double gout141 = 0;
    double gout142 = 0;
    double gout143 = 0;
    double gout144 = 0;
    double gout145 = 0;
    double gout146 = 0;
    double gout147 = 0;
    double gout148 = 0;
    double gout149 = 0;
    double gout150 = 0;
    double gout151 = 0;
    double gout152 = 0;
    double gout153 = 0;
    double gout154 = 0;
    double gout155 = 0;
    double gout156 = 0;
    double gout157 = 0;
    double gout158 = 0;
    double gout159 = 0;
    double gout160 = 0;
    double gout161 = 0;
    double gout162 = 0;
    double gout163 = 0;
    double gout164 = 0;
    double gout165 = 0;
    double gout166 = 0;
    double gout167 = 0;
    double gout168 = 0;
    double gout169 = 0;
    double gout170 = 0;
    double gout171 = 0;
    double gout172 = 0;
    double gout173 = 0;
    double gout174 = 0;
    double gout175 = 0;
    double gout176 = 0;
    double gout177 = 0;
    double gout178 = 0;
    double gout179 = 0;

    double xi = bas_x[ish];
    double yi = bas_y[ish];
    double zi = bas_z[ish];
    double ABx = xi - bas_x[jsh];
    double ABy = yi - bas_y[jsh];
    double ABz = zi - bas_z[jsh];
    double xk = bas_x[ksh];
    double yk = bas_y[ksh];
    double zk = bas_z[ksh];
    double CDx = xk - bas_x[lsh];
    double CDy = yk - bas_y[lsh];
    double CDz = zk - bas_z[lsh];
    prim_ij0 = prim_ij;
    prim_ij1 = prim_ij + nprim_ij;
    prim_kl0 = prim_kl;
    prim_kl1 = prim_kl + nprim_kl;
    double rw[6];
    int irys;
    for (ij = prim_ij0; ij < prim_ij1; ++ij) {
        double alpha = i_exponent[ij];
        double beta = j_exponent[ij];
        double aij = a12[ij];
        double eij = e12[ij];
        double xij = x12[ij];
        double yij = y12[ij];
        double zij = z12[ij];
    for (kl = prim_kl0; kl < prim_kl1; ++kl) {
        double akl = a12[kl];
        double ekl = e12[kl];
        double xkl = x12[kl];
        double ykl = y12[kl];
        double zkl = z12[kl];
        double xijxkl = xij - xkl;
        double yijykl = yij - ykl;
        double zijzkl = zij - zkl;
        double aijkl = aij + akl;
        double a1 = aij * akl;
        double a0 = a1 / aijkl;
        double theta = omega > 0.0 ? omega * omega / (omega * omega + a0) : 1.0; 
        a0 *= theta;
        double x = a0 * (xijxkl * xijxkl + yijykl * yijykl + zijzkl * zijzkl);
        double fac = norm * eij * ekl * sqrt(a0 / (a1 * a1 * a1));
        //double fac = norm * eij * ekl / (sqrt(aijkl) * a1);

        GINTrys_root<3>(x, rw);
        GINTscale_u<3>(rw, theta);
      for (irys = 0; irys < 3; ++irys) {
            double weight0 = rw[irys+3] * fac;
            double root0 = rw[irys];
            double u2 = a0 * root0;
            double tmp4 = .5 / (u2 * aijkl + a1);
            double B00 = u2 * tmp4;
            double tmp1 = 2 * B00;

            double tmp2 = tmp1 * akl;
            double C00x = xij - xi - tmp2 * xijxkl;
            double C00y = yij - yi - tmp2 * yijykl;
            double C00z = zij - zi - tmp2 * zijzkl;
            double B01 = B00 + tmp4 * aij;
            double tmp3 = tmp1 * aij;
            double D00x = xkl - xk + tmp3 * xijxkl;
            double D00y = ykl - yk + tmp3 * yijykl;
            double D00z = zkl - zk + tmp3 * zijzkl;

            double g1 = B00+(C00x*D00x);
            double g2 = B01+D00x*D00x;
            double g3 = 2*B00*D00x;
            double g4 = C00x*g2;
            double g5 = g3+g4;
            double g6 = 3*B01*D00x;
            double g7 = g6+D00x*D00x*D00x;
            double g8 = 3*B00*g2;
            double g9 = 3*B01;
            double g10 = g9+D00x*D00x;
            double g11 = C00x*D00x*g10;
            double g12 = g8+g11;
            double g13 = ABx+C00x;
            double g14 = g13*D00x;
            double g15 = B00+g14;
            double g16 = g13*g2;
            double g17 = g3+g16;
            double g18 = g13*D00x*g10;
            double g19 = g8+g18;
            double g20 = CDx+D00x;
            double g21 = C00x*g20;
            double g22 = B00+g21;
            double g23 = D00x*g20;
            double g24 = B01+g23;
            double g26 = C00x*D00x*g20;
            double g28 = CDx+(2*D00x);
            double g29 = B00*g28;
            double g30 = (B01*C00x)+g26+g29;
            double g32 = 3*D00x;
            double g33 = CDx+g32;
            double g35 = (D00x*D00x*g20)+(B01*g33);
            double g36 = 3*B00*B01;
            double g40 = (2*CDx)+g32;
            double g42 = g36+(C00x*D00x*D00x*g20)+(B01*C00x*g33)+(B00*D00x*g40);
            double g43 = 3*B01*B01;
            double g46 = g43+(D00x*D00x*D00x*g20)+(3*B01*D00x*g28);
            double g49 = 4*D00x;
            double g59 = (3*B01*B01*C00x)+(3*B01*((C00x*D00x*g28)+(B00*(CDx+g49))))+(D00x*D00x*(g26+(B00*((3*CDx)+g49))));
            double g61 = B00+(g13*g20);
            double g63 = g29+(g13*g24);
            double g68 = (g13*g35)+(B00*(g9+(D00x*g40)));
            double g70 = B00*CDx;
            double g73 = 4*B00;
            double g75 = g73+(g13*CDx);
            double g82 = (3*B01*((B01*g13)+g70))+(3*B01*g75*D00x)+(3*((2*B01*g13)+g70)*D00x*D00x)+(g75*D00x*D00x*D00x)+(g13*D00x*D00x*D00x*D00x);
            double g84 = B00+(C00y*D00y);
            double g85 = B01+D00y*D00y;
            double g86 = 2*B00*D00y;
            double g88 = g86+(C00y*g85);
            double g90 = (3*B01*D00y)+D00y*D00y*D00y;
            double g91 = 3*B00*g85;
            double g92 = g9+D00y*D00y;
            double g94 = g91+(C00y*D00y*g92);
            double g95 = ABy+C00y;
            double g97 = B00+(g95*D00y);
            double g99 = g86+(g95*g85);
            double g101 = g91+(g95*D00y*g92);
            double g102 = CDy+D00y;
            double g104 = B00+(C00y*g102);
            double g106 = B01+(D00y*g102);
            double g108 = C00y*D00y*g102;
            double g110 = CDy+(2*D00y);
            double g111 = B00*g110;
            double g112 = (B01*C00y)+g108+g111;
            double g114 = 3*D00y;
            double g115 = CDy+g114;
            double g117 = (D00y*D00y*g102)+(B01*g115);
            double g121 = (2*CDy)+g114;
            double g123 = g36+(C00y*D00y*D00y*g102)+(B01*C00y*g115)+(B00*D00y*g121);
            double g126 = g43+(D00y*D00y*D00y*g102)+(3*B01*D00y*g110);
            double g129 = 4*D00y;
            double g139 = (3*B01*B01*C00y)+(3*B01*((C00y*D00y*g110)+(B00*(CDy+g129))))+(D00y*D00y*(g108+(B00*((3*CDy)+g129))));
            double g141 = B00+(g95*g102);
            double g143 = g111+(g95*g106);
            double g148 = (g95*g117)+(B00*(g9+(D00y*g121)));
            double g150 = B00*CDy;
            double g154 = g73+(g95*CDy);
            double g161 = (3*B01*((B01*g95)+g150))+(3*B01*g154*D00y)+(3*((2*B01*g95)+g150)*D00y*D00y)+(g154*D00y*D00y*D00y)+(g95*D00y*D00y*D00y*D00y);
            double g163 = B00+(C00z*D00z);
            double g164 = B01+D00z*D00z;
            double g165 = 2*B00*D00z;
            double g167 = g165+(C00z*g164);
            double g169 = (3*B01*D00z)+D00z*D00z*D00z;
            double g170 = 3*B00*g164;
            double g171 = g9+D00z*D00z;
            double g173 = g170+(C00z*D00z*g171);
            double g174 = ABz+C00z;
            double g176 = B00+(g174*D00z);
            double g178 = g165+(g174*g164);
            double g180 = g170+(g174*D00z*g171);
            double g181 = CDz+D00z;
            double g183 = B00+(C00z*g181);
            double g185 = B01+(D00z*g181);
            double g187 = C00z*D00z*g181;
            double g189 = CDz+(2*D00z);
            double g190 = B00*g189;
            double g191 = (B01*C00z)+g187+g190;
            double g193 = 3*D00z;
            double g194 = CDz+g193;
            double g196 = (D00z*D00z*g181)+(B01*g194);
            double g200 = (2*CDz)+g193;
            double g202 = g36+(C00z*D00z*D00z*g181)+(B01*C00z*g194)+(B00*D00z*g200);
            double g205 = g43+(D00z*D00z*D00z*g181)+(3*B01*D00z*g189);
            double g208 = 4*D00z;
            double g218 = (3*B01*B01*C00z)+(3*B01*((C00z*D00z*g189)+(B00*(CDz+g208))))+(D00z*D00z*(g187+(B00*((3*CDz)+g208))));
            double g220 = B00+(g174*g181);
            double g222 = g190+(g174*g185);
            double g227 = (g174*g196)+(B00*(g9+(D00z*g200)));
            double g229 = B00*CDz;
            double g233 = g73+(g174*CDz);
            double g240 = (3*B01*((B01*g174)+g229))+(3*B01*g233*D00z)+(3*((2*B01*g174)+g229)*D00z*D00z)+(g233*D00z*D00z*D00z)+(g174*D00z*D00z*D00z*D00z);

            gout0 += (2*alpha*g59) * weight0;
            gout1 += (2*alpha*g12) * (g102) * weight0;
            gout2 += (2*alpha*g12) * (g181) * weight0;
            gout3 += (2*alpha*g42) * (D00y) * weight0;
            gout4 += (2*alpha*g5) * (g106) * weight0;
            gout5 += (2*alpha*g5) * (D00y) * (g181) * weight0;
            gout6 += (2*alpha*g42) * (D00z) * weight0;
            gout7 += (2*alpha*g5) * (g102) * (D00z) * weight0;
            gout8 += (2*alpha*g5) * (g185) * weight0;
            gout9 += (2*alpha*g30) * (g85) * weight0;
            gout10 += (2*alpha*g1) * (g117) * weight0;
            gout11 += (2*alpha*g1) * (g85) * (g181) * weight0;
            gout12 += (2*alpha*g30) * (D00y) * (D00z) * weight0;
            gout13 += (2*alpha*g1) * (g106) * (D00z) * weight0;
            gout14 += (2*alpha*g1) * (D00y) * (g185) * weight0;
            gout15 += (2*alpha*g30) * (g164) * weight0;
            gout16 += (2*alpha*g1) * (g102) * (g164) * weight0;
            gout17 += (2*alpha*g1) * (g196) * weight0;
            gout18 += (2*alpha*g22) * (g90) * weight0;
            gout19 += (2*alpha*C00x) * (g126) * weight0;
            gout20 += (2*alpha*C00x) * (g90) * (g181) * weight0;
            gout21 += (2*alpha*g22) * (g85) * (D00z) * weight0;
            gout22 += (2*alpha*C00x) * (g117) * (D00z) * weight0;
            gout23 += (2*alpha*C00x) * (g85) * (g185) * weight0;
            gout24 += (2*alpha*g22) * (D00y) * (g164) * weight0;
            gout25 += (2*alpha*C00x) * (g106) * (g164) * weight0;
            gout26 += (2*alpha*C00x) * (D00y) * (g196) * weight0;
            gout27 += (2*alpha*g22) * (g169) * weight0;
            gout28 += (2*alpha*C00x) * (g102) * (g169) * weight0;
            gout29 += (2*alpha*C00x) * (g205) * weight0;
            gout30 += (g46) * (2*alpha*C00y) * weight0;
            gout31 += (g7) * (2*alpha*g104) * weight0;
            gout32 += (g7) * (2*alpha*C00y) * (g181) * weight0;
            gout33 += (g35) * (2*alpha*g84) * weight0;
            gout34 += (g2) * (2*alpha*g112) * weight0;
            gout35 += (g2) * (2*alpha*g84) * (g181) * weight0;
            gout36 += (g35) * (2*alpha*C00y) * (D00z) * weight0;
            gout37 += (g2) * (2*alpha*g104) * (D00z) * weight0;
            gout38 += (g2) * (2*alpha*C00y) * (g185) * weight0;
            gout39 += (g24) * (2*alpha*g88) * weight0;
            gout40 += (D00x) * (2*alpha*g123) * weight0;
            gout41 += (D00x) * (2*alpha*g88) * (g181) * weight0;
            gout42 += (g24) * (2*alpha*g84) * (D00z) * weight0;
            gout43 += (D00x) * (2*alpha*g112) * (D00z) * weight0;
            gout44 += (D00x) * (2*alpha*g84) * (g185) * weight0;
            gout45 += (g24) * (2*alpha*C00y) * (g164) * weight0;
            gout46 += (D00x) * (2*alpha*g104) * (g164) * weight0;
            gout47 += (D00x) * (2*alpha*C00y) * (g196) * weight0;
            gout48 += (g20) * (2*alpha*g94) * weight0;
            gout49 += (2*alpha*g139) * weight0;
            gout50 += (2*alpha*g94) * (g181) * weight0;
            gout51 += (g20) * (2*alpha*g88) * (D00z) * weight0;
            gout52 += (2*alpha*g123) * (D00z) * weight0;
            gout53 += (2*alpha*g88) * (g185) * weight0;
            gout54 += (g20) * (2*alpha*g84) * (g164) * weight0;
            gout55 += (2*alpha*g112) * (g164) * weight0;
            gout56 += (2*alpha*g84) * (g196) * weight0;
            gout57 += (g20) * (2*alpha*C00y) * (g169) * weight0;
            gout58 += (2*alpha*g104) * (g169) * weight0;
            gout59 += (2*alpha*C00y) * (g205) * weight0;
            gout60 += (g46) * (2*alpha*C00z) * weight0;
            gout61 += (g7) * (g102) * (2*alpha*C00z) * weight0;
            gout62 += (g7) * (2*alpha*g183) * weight0;
            gout63 += (g35) * (D00y) * (2*alpha*C00z) * weight0;
            gout64 += (g2) * (g106) * (2*alpha*C00z) * weight0;
            gout65 += (g2) * (D00y) * (2*alpha*g183) * weight0;
            gout66 += (g35) * (2*alpha*g163) * weight0;
            gout67 += (g2) * (g102) * (2*alpha*g163) * weight0;
            gout68 += (g2) * (2*alpha*g191) * weight0;
            gout69 += (g24) * (g85) * (2*alpha*C00z) * weight0;
            gout70 += (D00x) * (g117) * (2*alpha*C00z) * weight0;
            gout71 += (D00x) * (g85) * (2*alpha*g183) * weight0;
            gout72 += (g24) * (D00y) * (2*alpha*g163) * weight0;
            gout73 += (D00x) * (g106) * (2*alpha*g163) * weight0;
            gout74 += (D00x) * (D00y) * (2*alpha*g191) * weight0;
            gout75 += (g24) * (2*alpha*g167) * weight0;
            gout76 += (D00x) * (g102) * (2*alpha*g167) * weight0;
            gout77 += (D00x) * (2*alpha*g202) * weight0;
            gout78 += (g20) * (g90) * (2*alpha*C00z) * weight0;
            gout79 += (g126) * (2*alpha*C00z) * weight0;
            gout80 += (g90) * (2*alpha*g183) * weight0;
            gout81 += (g20) * (g85) * (2*alpha*g163) * weight0;
            gout82 += (g117) * (2*alpha*g163) * weight0;
            gout83 += (g85) * (2*alpha*g191) * weight0;
            gout84 += (g20) * (D00y) * (2*alpha*g167) * weight0;
            gout85 += (g106) * (2*alpha*g167) * weight0;
            gout86 += (D00y) * (2*alpha*g202) * weight0;
            gout87 += (g20) * (2*alpha*g173) * weight0;
            gout88 += (g102) * (2*alpha*g173) * weight0;
            gout89 += (2*alpha*g218) * weight0;
            gout90 += (2*beta*g82) * weight0;
            gout91 += (2*beta*g19) * (g102) * weight0;
            gout92 += (2*beta*g19) * (g181) * weight0;
            gout93 += (2*beta*g68) * (D00y) * weight0;
            gout94 += (2*beta*g17) * (g106) * weight0;
            gout95 += (2*beta*g17) * (D00y) * (g181) * weight0;
            gout96 += (2*beta*g68) * (D00z) * weight0;
            gout97 += (2*beta*g17) * (g102) * (D00z) * weight0;
            gout98 += (2*beta*g17) * (g185) * weight0;
            gout99 += (2*beta*g63) * (g85) * weight0;
            gout100 += (2*beta*g15) * (g117) * weight0;
            gout101 += (2*beta*g15) * (g85) * (g181) * weight0;
            gout102 += (2*beta*g63) * (D00y) * (D00z) * weight0;
            gout103 += (2*beta*g15) * (g106) * (D00z) * weight0;
            gout104 += (2*beta*g15) * (D00y) * (g185) * weight0;
            gout105 += (2*beta*g63) * (g164) * weight0;
            gout106 += (2*beta*g15) * (g102) * (g164) * weight0;
            gout107 += (2*beta*g15) * (g196) * weight0;
            gout108 += (2*beta*g61) * (g90) * weight0;
            gout109 += (2*beta*g13) * (g126) * weight0;
            gout110 += (2*beta*g13) * (g90) * (g181) * weight0;
            gout111 += (2*beta*g61) * (g85) * (D00z) * weight0;
            gout112 += (2*beta*g13) * (g117) * (D00z) * weight0;
            gout113 += (2*beta*g13) * (g85) * (g185) * weight0;
            gout114 += (2*beta*g61) * (D00y) * (g164) * weight0;
            gout115 += (2*beta*g13) * (g106) * (g164) * weight0;
            gout116 += (2*beta*g13) * (D00y) * (g196) * weight0;
            gout117 += (2*beta*g61) * (g169) * weight0;
            gout118 += (2*beta*g13) * (g102) * (g169) * weight0;
            gout119 += (2*beta*g13) * (g205) * weight0;
            gout120 += (g46) * (2*beta*g95) * weight0;
            gout121 += (g7) * (2*beta*g141) * weight0;
            gout122 += (g7) * (2*beta*g95) * (g181) * weight0;
            gout123 += (g35) * (2*beta*g97) * weight0;
            gout124 += (g2) * (2*beta*g143) * weight0;
            gout125 += (g2) * (2*beta*g97) * (g181) * weight0;
            gout126 += (g35) * (2*beta*g95) * (D00z) * weight0;
            gout127 += (g2) * (2*beta*g141) * (D00z) * weight0;
            gout128 += (g2) * (2*beta*g95) * (g185) * weight0;
            gout129 += (g24) * (2*beta*g99) * weight0;
            gout130 += (D00x) * (2*beta*g148) * weight0;
            gout131 += (D00x) * (2*beta*g99) * (g181) * weight0;
            gout132 += (g24) * (2*beta*g97) * (D00z) * weight0;
            gout133 += (D00x) * (2*beta*g143) * (D00z) * weight0;
            gout134 += (D00x) * (2*beta*g97) * (g185) * weight0;
            gout135 += (g24) * (2*beta*g95) * (g164) * weight0;
            gout136 += (D00x) * (2*beta*g141) * (g164) * weight0;
            gout137 += (D00x) * (2*beta*g95) * (g196) * weight0;
            gout138 += (g20) * (2*beta*g101) * weight0;
            gout139 += (2*beta*g161) * weight0;
            gout140 += (2*beta*g101) * (g181) * weight0;
            gout141 += (g20) * (2*beta*g99) * (D00z) * weight0;
            gout142 += (2*beta*g148) * (D00z) * weight0;
            gout143 += (2*beta*g99) * (g185) * weight0;
            gout144 += (g20) * (2*beta*g97) * (g164) * weight0;
            gout145 += (2*beta*g143) * (g164) * weight0;
            gout146 += (2*beta*g97) * (g196) * weight0;
            gout147 += (g20) * (2*beta*g95) * (g169) * weight0;
            gout148 += (2*beta*g141) * (g169) * weight0;
            gout149 += (2*beta*g95) * (g205) * weight0;
            gout150 += (g46) * (2*beta*g174) * weight0;
            gout151 += (g7) * (g102) * (2*beta*g174) * weight0;
            gout152 += (g7) * (2*beta*g220) * weight0;
            gout153 += (g35) * (D00y) * (2*beta*g174) * weight0;
            gout154 += (g2) * (g106) * (2*beta*g174) * weight0;
            gout155 += (g2) * (D00y) * (2*beta*g220) * weight0;
            gout156 += (g35) * (2*beta*g176) * weight0;
            gout157 += (g2) * (g102) * (2*beta*g176) * weight0;
            gout158 += (g2) * (2*beta*g222) * weight0;
            gout159 += (g24) * (g85) * (2*beta*g174) * weight0;
            gout160 += (D00x) * (g117) * (2*beta*g174) * weight0;
            gout161 += (D00x) * (g85) * (2*beta*g220) * weight0;
            gout162 += (g24) * (D00y) * (2*beta*g176) * weight0;
            gout163 += (D00x) * (g106) * (2*beta*g176) * weight0;
            gout164 += (D00x) * (D00y) * (2*beta*g222) * weight0;
            gout165 += (g24) * (2*beta*g178) * weight0;
            gout166 += (D00x) * (g102) * (2*beta*g178) * weight0;
            gout167 += (D00x) * (2*beta*g227) * weight0;
            gout168 += (g20) * (g90) * (2*beta*g174) * weight0;
            gout169 += (g126) * (2*beta*g174) * weight0;
            gout170 += (g90) * (2*beta*g220) * weight0;
            gout171 += (g20) * (g85) * (2*beta*g176) * weight0;
            gout172 += (g117) * (2*beta*g176) * weight0;
            gout173 += (g85) * (2*beta*g222) * weight0;
            gout174 += (g20) * (D00y) * (2*beta*g178) * weight0;
            gout175 += (g106) * (2*beta*g178) * weight0;
            gout176 += (D00y) * (2*beta*g227) * weight0;
            gout177 += (g20) * (2*beta*g180) * weight0;
            gout178 += (g102) * (2*beta*g180) * weight0;
            gout179 += (2*beta*g240) * weight0;
        }
    } }

    int *ao_loc = c_bpcache.ao_loc;
    int i0 = ao_loc[ish];
    int j0 = ao_loc[jsh];
    int k0 = ao_loc[ksh];
    int l0 = ao_loc[lsh];
    int n_dm = jk.n_dm;
    int nao = jk.nao;
    size_t nao2 = nao * nao;
    double* __restrict__ dm = jk.dm;
    double *vj = jk.vj;
    double *vk = jk.vk;
    double d_0, d_1, d_2, d_3, d_4, d_5, d_6, d_7, d_8, d_9, d_10, d_11, d_12, d_13, d_14, d_15, d_16, d_17, d_18, d_19, d_20, d_21, d_22, d_23, d_24, d_25, d_26, d_27, d_28, d_29;

    for (int i_dm = 0; i_dm < n_dm; ++i_dm) {
        if (vj != NULL) {
            d_0 = dm[(k0+0)+nao*(l0+0)];
            d_1 = dm[(k0+0)+nao*(l0+1)];
            d_2 = dm[(k0+0)+nao*(l0+2)];
            d_3 = dm[(k0+1)+nao*(l0+0)];
            d_4 = dm[(k0+1)+nao*(l0+1)];
            d_5 = dm[(k0+1)+nao*(l0+2)];
            d_6 = dm[(k0+2)+nao*(l0+0)];
            d_7 = dm[(k0+2)+nao*(l0+1)];
            d_8 = dm[(k0+2)+nao*(l0+2)];
            d_9 = dm[(k0+3)+nao*(l0+0)];
            d_10 = dm[(k0+3)+nao*(l0+1)];
            d_11 = dm[(k0+3)+nao*(l0+2)];
            d_12 = dm[(k0+4)+nao*(l0+0)];
            d_13 = dm[(k0+4)+nao*(l0+1)];
            d_14 = dm[(k0+4)+nao*(l0+2)];
            d_15 = dm[(k0+5)+nao*(l0+0)];
            d_16 = dm[(k0+5)+nao*(l0+1)];
            d_17 = dm[(k0+5)+nao*(l0+2)];
            d_18 = dm[(k0+6)+nao*(l0+0)];
            d_19 = dm[(k0+6)+nao*(l0+1)];
            d_20 = dm[(k0+6)+nao*(l0+2)];
            d_21 = dm[(k0+7)+nao*(l0+0)];
            d_22 = dm[(k0+7)+nao*(l0+1)];
            d_23 = dm[(k0+7)+nao*(l0+2)];
            d_24 = dm[(k0+8)+nao*(l0+0)];
            d_25 = dm[(k0+8)+nao*(l0+1)];
            d_26 = dm[(k0+8)+nao*(l0+2)];
            d_27 = dm[(k0+9)+nao*(l0+0)];
            d_28 = dm[(k0+9)+nao*(l0+1)];
            d_29 = dm[(k0+9)+nao*(l0+2)];
            atomicAdd(vj+(i0+0)+nao*(j0+0), gout0*d_0+gout1*d_1+gout2*d_2+gout3*d_3+gout4*d_4+gout5*d_5+gout6*d_6+gout7*d_7+gout8*d_8+gout9*d_9+gout10*d_10+gout11*d_11+gout12*d_12+gout13*d_13+gout14*d_14+gout15*d_15+gout16*d_16+gout17*d_17+gout18*d_18+gout19*d_19+gout20*d_20+gout21*d_21+gout22*d_22+gout23*d_23+gout24*d_24+gout25*d_25+gout26*d_26+gout27*d_27+gout28*d_28+gout29*d_29);
            atomicAdd(vj+(i0+0)+nao*(j0+0)+nao2, gout30*d_0+gout31*d_1+gout32*d_2+gout33*d_3+gout34*d_4+gout35*d_5+gout36*d_6+gout37*d_7+gout38*d_8+gout39*d_9+gout40*d_10+gout41*d_11+gout42*d_12+gout43*d_13+gout44*d_14+gout45*d_15+gout46*d_16+gout47*d_17+gout48*d_18+gout49*d_19+gout50*d_20+gout51*d_21+gout52*d_22+gout53*d_23+gout54*d_24+gout55*d_25+gout56*d_26+gout57*d_27+gout58*d_28+gout59*d_29);
            atomicAdd(vj+(i0+0)+nao*(j0+0)+2*nao2, gout60*d_0+gout61*d_1+gout62*d_2+gout63*d_3+gout64*d_4+gout65*d_5+gout66*d_6+gout67*d_7+gout68*d_8+gout69*d_9+gout70*d_10+gout71*d_11+gout72*d_12+gout73*d_13+gout74*d_14+gout75*d_15+gout76*d_16+gout77*d_17+gout78*d_18+gout79*d_19+gout80*d_20+gout81*d_21+gout82*d_22+gout83*d_23+gout84*d_24+gout85*d_25+gout86*d_26+gout87*d_27+gout88*d_28+gout89*d_29);
            atomicAdd(vj+nao*(i0+0)+(j0+0), gout90*d_0+gout91*d_1+gout92*d_2+gout93*d_3+gout94*d_4+gout95*d_5+gout96*d_6+gout97*d_7+gout98*d_8+gout99*d_9+gout100*d_10+gout101*d_11+gout102*d_12+gout103*d_13+gout104*d_14+gout105*d_15+gout106*d_16+gout107*d_17+gout108*d_18+gout109*d_19+gout110*d_20+gout111*d_21+gout112*d_22+gout113*d_23+gout114*d_24+gout115*d_25+gout116*d_26+gout117*d_27+gout118*d_28+gout119*d_29);
            atomicAdd(vj+nao*(i0+0)+(j0+0)+nao2, gout120*d_0+gout121*d_1+gout122*d_2+gout123*d_3+gout124*d_4+gout125*d_5+gout126*d_6+gout127*d_7+gout128*d_8+gout129*d_9+gout130*d_10+gout131*d_11+gout132*d_12+gout133*d_13+gout134*d_14+gout135*d_15+gout136*d_16+gout137*d_17+gout138*d_18+gout139*d_19+gout140*d_20+gout141*d_21+gout142*d_22+gout143*d_23+gout144*d_24+gout145*d_25+gout146*d_26+gout147*d_27+gout148*d_28+gout149*d_29);
            atomicAdd(vj+nao*(i0+0)+(j0+0)+2*nao2, gout150*d_0+gout151*d_1+gout152*d_2+gout153*d_3+gout154*d_4+gout155*d_5+gout156*d_6+gout157*d_7+gout158*d_8+gout159*d_9+gout160*d_10+gout161*d_11+gout162*d_12+gout163*d_13+gout164*d_14+gout165*d_15+gout166*d_16+gout167*d_17+gout168*d_18+gout169*d_19+gout170*d_20+gout171*d_21+gout172*d_22+gout173*d_23+gout174*d_24+gout175*d_25+gout176*d_26+gout177*d_27+gout178*d_28+gout179*d_29);
            vj += 3*nao2;
        }
        if (vk != NULL) {
            // ijkl, jk -> il
            d_0 = dm[(j0+0)+nao*(k0+0)];
            d_1 = dm[(j0+0)+nao*(k0+1)];
            d_2 = dm[(j0+0)+nao*(k0+2)];
            d_3 = dm[(j0+0)+nao*(k0+3)];
            d_4 = dm[(j0+0)+nao*(k0+4)];
            d_5 = dm[(j0+0)+nao*(k0+5)];
            d_6 = dm[(j0+0)+nao*(k0+6)];
            d_7 = dm[(j0+0)+nao*(k0+7)];
            d_8 = dm[(j0+0)+nao*(k0+8)];
            d_9 = dm[(j0+0)+nao*(k0+9)];
            atomicAdd(vk+(i0+0)+nao*(l0+0), gout0*d_0+gout3*d_1+gout6*d_2+gout9*d_3+gout12*d_4+gout15*d_5+gout18*d_6+gout21*d_7+gout24*d_8+gout27*d_9);
            atomicAdd(vk+(i0+0)+nao*(l0+1), gout1*d_0+gout4*d_1+gout7*d_2+gout10*d_3+gout13*d_4+gout16*d_5+gout19*d_6+gout22*d_7+gout25*d_8+gout28*d_9);
            atomicAdd(vk+(i0+0)+nao*(l0+2), gout2*d_0+gout5*d_1+gout8*d_2+gout11*d_3+gout14*d_4+gout17*d_5+gout20*d_6+gout23*d_7+gout26*d_8+gout29*d_9);
            atomicAdd(vk+(i0+0)+nao*(l0+0)+nao2, gout30*d_0+gout33*d_1+gout36*d_2+gout39*d_3+gout42*d_4+gout45*d_5+gout48*d_6+gout51*d_7+gout54*d_8+gout57*d_9);
            atomicAdd(vk+(i0+0)+nao*(l0+1)+nao2, gout31*d_0+gout34*d_1+gout37*d_2+gout40*d_3+gout43*d_4+gout46*d_5+gout49*d_6+gout52*d_7+gout55*d_8+gout58*d_9);
            atomicAdd(vk+(i0+0)+nao*(l0+2)+nao2, gout32*d_0+gout35*d_1+gout38*d_2+gout41*d_3+gout44*d_4+gout47*d_5+gout50*d_6+gout53*d_7+gout56*d_8+gout59*d_9);
            atomicAdd(vk+(i0+0)+nao*(l0+0)+2*nao2, gout60*d_0+gout63*d_1+gout66*d_2+gout69*d_3+gout72*d_4+gout75*d_5+gout78*d_6+gout81*d_7+gout84*d_8+gout87*d_9);
            atomicAdd(vk+(i0+0)+nao*(l0+1)+2*nao2, gout61*d_0+gout64*d_1+gout67*d_2+gout70*d_3+gout73*d_4+gout76*d_5+gout79*d_6+gout82*d_7+gout85*d_8+gout88*d_9);
            atomicAdd(vk+(i0+0)+nao*(l0+2)+2*nao2, gout62*d_0+gout65*d_1+gout68*d_2+gout71*d_3+gout74*d_4+gout77*d_5+gout80*d_6+gout83*d_7+gout86*d_8+gout89*d_9);
            // ijkl, jl -> ik
            d_0 = dm[(j0+0)+nao*(l0+0)];
            d_1 = dm[(j0+0)+nao*(l0+1)];
            d_2 = dm[(j0+0)+nao*(l0+2)];
            atomicAdd(vk+(i0+0)+nao*(k0+0), gout0*d_0+gout1*d_1+gout2*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+1), gout3*d_0+gout4*d_1+gout5*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+2), gout6*d_0+gout7*d_1+gout8*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+3), gout9*d_0+gout10*d_1+gout11*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+4), gout12*d_0+gout13*d_1+gout14*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+5), gout15*d_0+gout16*d_1+gout17*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+6), gout18*d_0+gout19*d_1+gout20*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+7), gout21*d_0+gout22*d_1+gout23*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+8), gout24*d_0+gout25*d_1+gout26*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+9), gout27*d_0+gout28*d_1+gout29*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+0)+nao2, gout30*d_0+gout31*d_1+gout32*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+1)+nao2, gout33*d_0+gout34*d_1+gout35*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+2)+nao2, gout36*d_0+gout37*d_1+gout38*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+3)+nao2, gout39*d_0+gout40*d_1+gout41*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+4)+nao2, gout42*d_0+gout43*d_1+gout44*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+5)+nao2, gout45*d_0+gout46*d_1+gout47*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+6)+nao2, gout48*d_0+gout49*d_1+gout50*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+7)+nao2, gout51*d_0+gout52*d_1+gout53*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+8)+nao2, gout54*d_0+gout55*d_1+gout56*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+9)+nao2, gout57*d_0+gout58*d_1+gout59*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+0)+2*nao2, gout60*d_0+gout61*d_1+gout62*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+1)+2*nao2, gout63*d_0+gout64*d_1+gout65*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+2)+2*nao2, gout66*d_0+gout67*d_1+gout68*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+3)+2*nao2, gout69*d_0+gout70*d_1+gout71*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+4)+2*nao2, gout72*d_0+gout73*d_1+gout74*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+5)+2*nao2, gout75*d_0+gout76*d_1+gout77*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+6)+2*nao2, gout78*d_0+gout79*d_1+gout80*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+7)+2*nao2, gout81*d_0+gout82*d_1+gout83*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+8)+2*nao2, gout84*d_0+gout85*d_1+gout86*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+9)+2*nao2, gout87*d_0+gout88*d_1+gout89*d_2);
            // ijkl, ik -> jl
            d_0 = dm[(i0+0)+nao*(k0+0)];
            d_1 = dm[(i0+0)+nao*(k0+1)];
            d_2 = dm[(i0+0)+nao*(k0+2)];
            d_3 = dm[(i0+0)+nao*(k0+3)];
            d_4 = dm[(i0+0)+nao*(k0+4)];
            d_5 = dm[(i0+0)+nao*(k0+5)];
            d_6 = dm[(i0+0)+nao*(k0+6)];
            d_7 = dm[(i0+0)+nao*(k0+7)];
            d_8 = dm[(i0+0)+nao*(k0+8)];
            d_9 = dm[(i0+0)+nao*(k0+9)];
            atomicAdd(vk+(j0+0)+nao*(l0+0), gout90*d_0+gout93*d_1+gout96*d_2+gout99*d_3+gout102*d_4+gout105*d_5+gout108*d_6+gout111*d_7+gout114*d_8+gout117*d_9);
            atomicAdd(vk+(j0+0)+nao*(l0+1), gout91*d_0+gout94*d_1+gout97*d_2+gout100*d_3+gout103*d_4+gout106*d_5+gout109*d_6+gout112*d_7+gout115*d_8+gout118*d_9);
            atomicAdd(vk+(j0+0)+nao*(l0+2), gout92*d_0+gout95*d_1+gout98*d_2+gout101*d_3+gout104*d_4+gout107*d_5+gout110*d_6+gout113*d_7+gout116*d_8+gout119*d_9);
            atomicAdd(vk+(j0+0)+nao*(l0+0)+nao2, gout120*d_0+gout123*d_1+gout126*d_2+gout129*d_3+gout132*d_4+gout135*d_5+gout138*d_6+gout141*d_7+gout144*d_8+gout147*d_9);
            atomicAdd(vk+(j0+0)+nao*(l0+1)+nao2, gout121*d_0+gout124*d_1+gout127*d_2+gout130*d_3+gout133*d_4+gout136*d_5+gout139*d_6+gout142*d_7+gout145*d_8+gout148*d_9);
            atomicAdd(vk+(j0+0)+nao*(l0+2)+nao2, gout122*d_0+gout125*d_1+gout128*d_2+gout131*d_3+gout134*d_4+gout137*d_5+gout140*d_6+gout143*d_7+gout146*d_8+gout149*d_9);
            atomicAdd(vk+(j0+0)+nao*(l0+0)+2*nao2, gout150*d_0+gout153*d_1+gout156*d_2+gout159*d_3+gout162*d_4+gout165*d_5+gout168*d_6+gout171*d_7+gout174*d_8+gout177*d_9);
            atomicAdd(vk+(j0+0)+nao*(l0+1)+2*nao2, gout151*d_0+gout154*d_1+gout157*d_2+gout160*d_3+gout163*d_4+gout166*d_5+gout169*d_6+gout172*d_7+gout175*d_8+gout178*d_9);
            atomicAdd(vk+(j0+0)+nao*(l0+2)+2*nao2, gout152*d_0+gout155*d_1+gout158*d_2+gout161*d_3+gout164*d_4+gout167*d_5+gout170*d_6+gout173*d_7+gout176*d_8+gout179*d_9);
            // ijkl, il -> jk
            d_0 = dm[(i0+0)+nao*(l0+0)];
            d_1 = dm[(i0+0)+nao*(l0+1)];
            d_2 = dm[(i0+0)+nao*(l0+2)];
            atomicAdd(vk+(j0+0)+nao*(k0+0), gout90*d_0+gout91*d_1+gout92*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+1), gout93*d_0+gout94*d_1+gout95*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+2), gout96*d_0+gout97*d_1+gout98*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+3), gout99*d_0+gout100*d_1+gout101*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+4), gout102*d_0+gout103*d_1+gout104*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+5), gout105*d_0+gout106*d_1+gout107*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+6), gout108*d_0+gout109*d_1+gout110*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+7), gout111*d_0+gout112*d_1+gout113*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+8), gout114*d_0+gout115*d_1+gout116*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+9), gout117*d_0+gout118*d_1+gout119*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+0)+nao2, gout120*d_0+gout121*d_1+gout122*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+1)+nao2, gout123*d_0+gout124*d_1+gout125*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+2)+nao2, gout126*d_0+gout127*d_1+gout128*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+3)+nao2, gout129*d_0+gout130*d_1+gout131*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+4)+nao2, gout132*d_0+gout133*d_1+gout134*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+5)+nao2, gout135*d_0+gout136*d_1+gout137*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+6)+nao2, gout138*d_0+gout139*d_1+gout140*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+7)+nao2, gout141*d_0+gout142*d_1+gout143*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+8)+nao2, gout144*d_0+gout145*d_1+gout146*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+9)+nao2, gout147*d_0+gout148*d_1+gout149*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+0)+2*nao2, gout150*d_0+gout151*d_1+gout152*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+1)+2*nao2, gout153*d_0+gout154*d_1+gout155*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+2)+2*nao2, gout156*d_0+gout157*d_1+gout158*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+3)+2*nao2, gout159*d_0+gout160*d_1+gout161*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+4)+2*nao2, gout162*d_0+gout163*d_1+gout164*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+5)+2*nao2, gout165*d_0+gout166*d_1+gout167*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+6)+2*nao2, gout168*d_0+gout169*d_1+gout170*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+7)+2*nao2, gout171*d_0+gout172*d_1+gout173*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+8)+2*nao2, gout174*d_0+gout175*d_1+gout176*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+9)+2*nao2, gout177*d_0+gout178*d_1+gout179*d_2);
            vk += 3*nao2;
        }
        dm += nao2;
    }
}

__global__
static void GINTint2e_ip1_jk_kernel_1011(GINTEnvVars envs, JKMatrix jk,
                                    BasisProdOffsets offsets)
{
    int ntasks_ij = offsets.ntasks_ij;
    int ntasks_kl = offsets.ntasks_kl;
    int task_ij = blockIdx.x * blockDim.x + threadIdx.x;
    int task_kl = blockIdx.y * blockDim.y + threadIdx.y;
    if (task_ij >= ntasks_ij || task_kl >= ntasks_kl) {
        return;
    }
    int bas_ij = offsets.bas_ij + task_ij;
    int bas_kl = offsets.bas_kl + task_kl;
    double norm = envs.fac;
    double omega = envs.omega;
    int *bas_pair2bra = c_bpcache.bas_pair2bra;
    int *bas_pair2ket = c_bpcache.bas_pair2ket;
    int ish = bas_pair2bra[bas_ij];
    int jsh = bas_pair2ket[bas_ij];
    int ksh = bas_pair2bra[bas_kl];
    int lsh = bas_pair2ket[bas_kl];
    int nprim_ij = envs.nprim_ij;
    int nprim_kl = envs.nprim_kl;
    int prim_ij = offsets.primitive_ij + task_ij * nprim_ij;
    int prim_kl = offsets.primitive_kl + task_kl * nprim_kl;

    double* __restrict__ a12 = c_bpcache.a12;
    double* __restrict__ e12 = c_bpcache.e12;
    double* __restrict__ x12 = c_bpcache.x12;
    double* __restrict__ y12 = c_bpcache.y12;
    double* __restrict__ z12 = c_bpcache.z12;
    double * __restrict__ i_exponent = c_bpcache.a1;
    double * __restrict__ j_exponent = c_bpcache.a2;

    int ij, kl;
    int prim_ij0, prim_ij1, prim_kl0, prim_kl1;
    int nbas = c_bpcache.nbas;
    double* __restrict__ bas_x = c_bpcache.bas_coords;
    double* __restrict__ bas_y = bas_x + nbas;
    double* __restrict__ bas_z = bas_y + nbas;

    double gout0 = 0;
    double gout1 = 0;
    double gout2 = 0;
    double gout3 = 0;
    double gout4 = 0;
    double gout5 = 0;
    double gout6 = 0;
    double gout7 = 0;
    double gout8 = 0;
    double gout9 = 0;
    double gout10 = 0;
    double gout11 = 0;
    double gout12 = 0;
    double gout13 = 0;
    double gout14 = 0;
    double gout15 = 0;
    double gout16 = 0;
    double gout17 = 0;
    double gout18 = 0;
    double gout19 = 0;
    double gout20 = 0;
    double gout21 = 0;
    double gout22 = 0;
    double gout23 = 0;
    double gout24 = 0;
    double gout25 = 0;
    double gout26 = 0;
    double gout27 = 0;
    double gout28 = 0;
    double gout29 = 0;
    double gout30 = 0;
    double gout31 = 0;
    double gout32 = 0;
    double gout33 = 0;
    double gout34 = 0;
    double gout35 = 0;
    double gout36 = 0;
    double gout37 = 0;
    double gout38 = 0;
    double gout39 = 0;
    double gout40 = 0;
    double gout41 = 0;
    double gout42 = 0;
    double gout43 = 0;
    double gout44 = 0;
    double gout45 = 0;
    double gout46 = 0;
    double gout47 = 0;
    double gout48 = 0;
    double gout49 = 0;
    double gout50 = 0;
    double gout51 = 0;
    double gout52 = 0;
    double gout53 = 0;
    double gout54 = 0;
    double gout55 = 0;
    double gout56 = 0;
    double gout57 = 0;
    double gout58 = 0;
    double gout59 = 0;
    double gout60 = 0;
    double gout61 = 0;
    double gout62 = 0;
    double gout63 = 0;
    double gout64 = 0;
    double gout65 = 0;
    double gout66 = 0;
    double gout67 = 0;
    double gout68 = 0;
    double gout69 = 0;
    double gout70 = 0;
    double gout71 = 0;
    double gout72 = 0;
    double gout73 = 0;
    double gout74 = 0;
    double gout75 = 0;
    double gout76 = 0;
    double gout77 = 0;
    double gout78 = 0;
    double gout79 = 0;
    double gout80 = 0;
    double gout81 = 0;
    double gout82 = 0;
    double gout83 = 0;
    double gout84 = 0;
    double gout85 = 0;
    double gout86 = 0;
    double gout87 = 0;
    double gout88 = 0;
    double gout89 = 0;
    double gout90 = 0;
    double gout91 = 0;
    double gout92 = 0;
    double gout93 = 0;
    double gout94 = 0;
    double gout95 = 0;
    double gout96 = 0;
    double gout97 = 0;
    double gout98 = 0;
    double gout99 = 0;
    double gout100 = 0;
    double gout101 = 0;
    double gout102 = 0;
    double gout103 = 0;
    double gout104 = 0;
    double gout105 = 0;
    double gout106 = 0;
    double gout107 = 0;
    double gout108 = 0;
    double gout109 = 0;
    double gout110 = 0;
    double gout111 = 0;
    double gout112 = 0;
    double gout113 = 0;
    double gout114 = 0;
    double gout115 = 0;
    double gout116 = 0;
    double gout117 = 0;
    double gout118 = 0;
    double gout119 = 0;
    double gout120 = 0;
    double gout121 = 0;
    double gout122 = 0;
    double gout123 = 0;
    double gout124 = 0;
    double gout125 = 0;
    double gout126 = 0;
    double gout127 = 0;
    double gout128 = 0;
    double gout129 = 0;
    double gout130 = 0;
    double gout131 = 0;
    double gout132 = 0;
    double gout133 = 0;
    double gout134 = 0;
    double gout135 = 0;
    double gout136 = 0;
    double gout137 = 0;
    double gout138 = 0;
    double gout139 = 0;
    double gout140 = 0;
    double gout141 = 0;
    double gout142 = 0;
    double gout143 = 0;
    double gout144 = 0;
    double gout145 = 0;
    double gout146 = 0;
    double gout147 = 0;
    double gout148 = 0;
    double gout149 = 0;
    double gout150 = 0;
    double gout151 = 0;
    double gout152 = 0;
    double gout153 = 0;
    double gout154 = 0;
    double gout155 = 0;
    double gout156 = 0;
    double gout157 = 0;
    double gout158 = 0;
    double gout159 = 0;
    double gout160 = 0;
    double gout161 = 0;

    double xi = bas_x[ish];
    double yi = bas_y[ish];
    double zi = bas_z[ish];
    double ABx = xi - bas_x[jsh];
    double ABy = yi - bas_y[jsh];
    double ABz = zi - bas_z[jsh];
    double xk = bas_x[ksh];
    double yk = bas_y[ksh];
    double zk = bas_z[ksh];
    double CDx = xk - bas_x[lsh];
    double CDy = yk - bas_y[lsh];
    double CDz = zk - bas_z[lsh];
    prim_ij0 = prim_ij;
    prim_ij1 = prim_ij + nprim_ij;
    prim_kl0 = prim_kl;
    prim_kl1 = prim_kl + nprim_kl;
    double rw[6];
    int irys;
    for (ij = prim_ij0; ij < prim_ij1; ++ij) {
        double alpha = i_exponent[ij];
        double beta = j_exponent[ij];
        double aij = a12[ij];
        double eij = e12[ij];
        double xij = x12[ij];
        double yij = y12[ij];
        double zij = z12[ij];
    for (kl = prim_kl0; kl < prim_kl1; ++kl) {
        double akl = a12[kl];
        double ekl = e12[kl];
        double xkl = x12[kl];
        double ykl = y12[kl];
        double zkl = z12[kl];
        double xijxkl = xij - xkl;
        double yijykl = yij - ykl;
        double zijzkl = zij - zkl;
        double aijkl = aij + akl;
        double a1 = aij * akl;
        double a0 = a1 / aijkl;
        double theta = omega > 0.0 ? omega * omega / (omega * omega + a0) : 1.0; 
        a0 *= theta;
        double x = a0 * (xijxkl * xijxkl + yijykl * yijykl + zijzkl * zijzkl);
        double fac = norm * eij * ekl * sqrt(a0 / (a1 * a1 * a1));
        //double fac = norm * eij * ekl / (sqrt(aijkl) * a1);

        GINTrys_root<3>(x, rw);
        GINTscale_u<3>(rw, theta);
      for (irys = 0; irys < 3; ++irys) {
            double weight0 = rw[irys+3] * fac;
            double root0 = rw[irys];
            double u2 = a0 * root0;
            double tmp4 = .5 / (u2 * aijkl + a1);
            double B00 = u2 * tmp4;
            double tmp1 = 2 * B00;
            double B10 = B00 + tmp4 * akl;
            double tmp2 = tmp1 * akl;
            double C00x = xij - xi - tmp2 * xijxkl;
            double C00y = yij - yi - tmp2 * yijykl;
            double C00z = zij - zi - tmp2 * zijzkl;
            double B01 = B00 + tmp4 * aij;
            double tmp3 = tmp1 * aij;
            double D00x = xkl - xk + tmp3 * xijxkl;
            double D00y = ykl - yk + tmp3 * yijykl;
            double D00z = zkl - zk + tmp3 * zijzkl;

            double g0 = B10+C00x*C00x;
            double g1 = C00x*D00x;
            double g2 = B00+g1;
            double g3 = 2*B00*C00x;
            double g4 = g0*D00x;
            double g5 = g3+g4;
            double g6 = ABx+C00x;
            double g7 = C00x*g6;
            double g8 = B10+g7;
            double g9 = g6*D00x;
            double g10 = B00+g9;
            double g11 = 2*C00x;
            double g12 = ABx+g11;
            double g15 = (B00*g12)+(g8*D00x);
            double g16 = CDx+D00x;
            double g18 = B00+(C00x*g16);
            double g19 = g0*g16;
            double g20 = g3+g19;
            double g22 = B01+(D00x*g16);
            double g26 = CDx+(2*D00x);
            double g27 = B00*g26;
            double g28 = (B01*C00x)+(C00x*D00x*g16)+g27;
            double g29 = 2*B00*B00;
            double g32 = g29+(2*B00*C00x*g26)+(g0*g22);
            double g34 = B00+(g6*g16);
            double g36 = g3+g19+(ABx*g18);
            double g38 = g27+(g6*g22);
            double g41 = g29+(B00*g12*g26)+(g8*g22);
            double g42 = B10+C00y*C00y;
            double g44 = B00+(C00y*D00y);
            double g45 = 2*B00*C00y;
            double g47 = g45+(g42*D00y);
            double g48 = ABy+C00y;
            double g50 = B10+(C00y*g48);
            double g52 = B00+(g48*D00y);
            double g54 = ABy+(2*C00y);
            double g57 = (B00*g54)+(g50*D00y);
            double g58 = CDy+D00y;
            double g60 = B00+(C00y*g58);
            double g61 = g42*g58;
            double g62 = g45+g61;
            double g64 = B01+(D00y*g58);
            double g68 = CDy+(2*D00y);
            double g69 = B00*g68;
            double g70 = (B01*C00y)+(C00y*D00y*g58)+g69;
            double g73 = g29+(2*B00*C00y*g68)+(g42*g64);
            double g75 = B00+(g48*g58);
            double g77 = g45+g61+(ABy*g60);
            double g79 = g69+(g48*g64);
            double g82 = g29+(B00*g54*g68)+(g50*g64);
            double g83 = B10+C00z*C00z;
            double g85 = B00+(C00z*D00z);
            double g86 = 2*B00*C00z;
            double g88 = g86+(g83*D00z);
            double g89 = ABz+C00z;
            double g91 = B10+(C00z*g89);
            double g93 = B00+(g89*D00z);
            double g95 = ABz+(2*C00z);
            double g98 = (B00*g95)+(g91*D00z);
            double g99 = CDz+D00z;
            double g101 = B00+(C00z*g99);
            double g102 = g83*g99;
            double g103 = g86+g102;
            double g105 = B01+(D00z*g99);
            double g109 = CDz+(2*D00z);
            double g110 = B00*g109;
            double g111 = (B01*C00z)+(C00z*D00z*g99)+g110;
            double g114 = g29+(2*B00*C00z*g109)+(g83*g105);
            double g116 = B00+(g89*g99);
            double g118 = g86+g102+(ABz*g101);
            double g120 = g110+(g89*g105);
            double g123 = g29+(B00*g95*g109)+(g91*g105);

            gout0 += (-g22 + 2*alpha*g32) * weight0;
            gout1 += (-D00x + 2*alpha*g5) * (g58) * weight0;
            gout2 += (-D00x + 2*alpha*g5) * (g99) * weight0;
            gout3 += (-g16 + 2*alpha*g20) * (D00y) * weight0;
            gout4 += (-1 + 2*alpha*g0) * (g64) * weight0;
            gout5 += (-1 + 2*alpha*g0) * (D00y) * (g99) * weight0;
            gout6 += (-g16 + 2*alpha*g20) * (D00z) * weight0;
            gout7 += (-1 + 2*alpha*g0) * (g58) * (D00z) * weight0;
            gout8 += (-1 + 2*alpha*g0) * (g105) * weight0;
            gout9 += (2*alpha*g28) * (C00y) * weight0;
            gout10 += (2*alpha*g2) * (g60) * weight0;
            gout11 += (2*alpha*g2) * (C00y) * (g99) * weight0;
            gout12 += (2*alpha*g18) * (g44) * weight0;
            gout13 += (2*alpha*C00x) * (g70) * weight0;
            gout14 += (2*alpha*C00x) * (g44) * (g99) * weight0;
            gout15 += (2*alpha*g18) * (C00y) * (D00z) * weight0;
            gout16 += (2*alpha*C00x) * (g60) * (D00z) * weight0;
            gout17 += (2*alpha*C00x) * (C00y) * (g105) * weight0;
            gout18 += (2*alpha*g28) * (C00z) * weight0;
            gout19 += (2*alpha*g2) * (g58) * (C00z) * weight0;
            gout20 += (2*alpha*g2) * (g101) * weight0;
            gout21 += (2*alpha*g18) * (D00y) * (C00z) * weight0;
            gout22 += (2*alpha*C00x) * (g64) * (C00z) * weight0;
            gout23 += (2*alpha*C00x) * (D00y) * (g101) * weight0;
            gout24 += (2*alpha*g18) * (g85) * weight0;
            gout25 += (2*alpha*C00x) * (g58) * (g85) * weight0;
            gout26 += (2*alpha*C00x) * (g111) * weight0;
            gout27 += (g28) * (2*alpha*C00y) * weight0;
            gout28 += (g2) * (2*alpha*g60) * weight0;
            gout29 += (g2) * (2*alpha*C00y) * (g99) * weight0;
            gout30 += (g18) * (2*alpha*g44) * weight0;
            gout31 += (C00x) * (2*alpha*g70) * weight0;
            gout32 += (C00x) * (2*alpha*g44) * (g99) * weight0;
            gout33 += (g18) * (2*alpha*C00y) * (D00z) * weight0;
            gout34 += (C00x) * (2*alpha*g60) * (D00z) * weight0;
            gout35 += (C00x) * (2*alpha*C00y) * (g105) * weight0;
            gout36 += (g22) * (-1 + 2*alpha*g42) * weight0;
            gout37 += (D00x) * (-g58 + 2*alpha*g62) * weight0;
            gout38 += (D00x) * (-1 + 2*alpha*g42) * (g99) * weight0;
            gout39 += (g16) * (-D00y + 2*alpha*g47) * weight0;
            gout40 += (-g64 + 2*alpha*g73) * weight0;
            gout41 += (-D00y + 2*alpha*g47) * (g99) * weight0;
            gout42 += (g16) * (-1 + 2*alpha*g42) * (D00z) * weight0;
            gout43 += (-g58 + 2*alpha*g62) * (D00z) * weight0;
            gout44 += (-1 + 2*alpha*g42) * (g105) * weight0;
            gout45 += (g22) * (2*alpha*C00y) * (C00z) * weight0;
            gout46 += (D00x) * (2*alpha*g60) * (C00z) * weight0;
            gout47 += (D00x) * (2*alpha*C00y) * (g101) * weight0;
            gout48 += (g16) * (2*alpha*g44) * (C00z) * weight0;
            gout49 += (2*alpha*g70) * (C00z) * weight0;
            gout50 += (2*alpha*g44) * (g101) * weight0;
            gout51 += (g16) * (2*alpha*C00y) * (g85) * weight0;
            gout52 += (2*alpha*g60) * (g85) * weight0;
            gout53 += (2*alpha*C00y) * (g111) * weight0;
            gout54 += (g28) * (2*alpha*C00z) * weight0;
            gout55 += (g2) * (g58) * (2*alpha*C00z) * weight0;
            gout56 += (g2) * (2*alpha*g101) * weight0;
            gout57 += (g18) * (D00y) * (2*alpha*C00z) * weight0;
            gout58 += (C00x) * (g64) * (2*alpha*C00z) * weight0;
            gout59 += (C00x) * (D00y) * (2*alpha*g101) * weight0;
            gout60 += (g18) * (2*alpha*g85) * weight0;
            gout61 += (C00x) * (g58) * (2*alpha*g85) * weight0;
            gout62 += (C00x) * (2*alpha*g111) * weight0;
            gout63 += (g22) * (C00y) * (2*alpha*C00z) * weight0;
            gout64 += (D00x) * (g60) * (2*alpha*C00z) * weight0;
            gout65 += (D00x) * (C00y) * (2*alpha*g101) * weight0;
            gout66 += (g16) * (g44) * (2*alpha*C00z) * weight0;
            gout67 += (g70) * (2*alpha*C00z) * weight0;
            gout68 += (g44) * (2*alpha*g101) * weight0;
            gout69 += (g16) * (C00y) * (2*alpha*g85) * weight0;
            gout70 += (g60) * (2*alpha*g85) * weight0;
            gout71 += (C00y) * (2*alpha*g111) * weight0;
            gout72 += (g22) * (-1 + 2*alpha*g83) * weight0;
            gout73 += (D00x) * (g58) * (-1 + 2*alpha*g83) * weight0;
            gout74 += (D00x) * (-g99 + 2*alpha*g103) * weight0;
            gout75 += (g16) * (D00y) * (-1 + 2*alpha*g83) * weight0;
            gout76 += (g64) * (-1 + 2*alpha*g83) * weight0;
            gout77 += (D00y) * (-g99 + 2*alpha*g103) * weight0;
            gout78 += (g16) * (-D00z + 2*alpha*g88) * weight0;
            gout79 += (g58) * (-D00z + 2*alpha*g88) * weight0;
            gout80 += (-g105 + 2*alpha*g114) * weight0;
            gout81 += (2*beta*g41) * weight0;
            gout82 += (2*beta*g15) * (g58) * weight0;
            gout83 += (2*beta*g15) * (g99) * weight0;
            gout84 += (2*beta*g36) * (D00y) * weight0;
            gout85 += (2*beta*g8) * (g64) * weight0;
            gout86 += (2*beta*g8) * (D00y) * (g99) * weight0;
            gout87 += (2*beta*g36) * (D00z) * weight0;
            gout88 += (2*beta*g8) * (g58) * (D00z) * weight0;
            gout89 += (2*beta*g8) * (g105) * weight0;
            gout90 += (2*beta*g38) * (C00y) * weight0;
            gout91 += (2*beta*g10) * (g60) * weight0;
            gout92 += (2*beta*g10) * (C00y) * (g99) * weight0;
            gout93 += (2*beta*g34) * (g44) * weight0;
            gout94 += (2*beta*g6) * (g70) * weight0;
            gout95 += (2*beta*g6) * (g44) * (g99) * weight0;
            gout96 += (2*beta*g34) * (C00y) * (D00z) * weight0;
            gout97 += (2*beta*g6) * (g60) * (D00z) * weight0;
            gout98 += (2*beta*g6) * (C00y) * (g105) * weight0;
            gout99 += (2*beta*g38) * (C00z) * weight0;
            gout100 += (2*beta*g10) * (g58) * (C00z) * weight0;
            gout101 += (2*beta*g10) * (g101) * weight0;
            gout102 += (2*beta*g34) * (D00y) * (C00z) * weight0;
            gout103 += (2*beta*g6) * (g64) * (C00z) * weight0;
            gout104 += (2*beta*g6) * (D00y) * (g101) * weight0;
            gout105 += (2*beta*g34) * (g85) * weight0;
            gout106 += (2*beta*g6) * (g58) * (g85) * weight0;
            gout107 += (2*beta*g6) * (g111) * weight0;
            gout108 += (g28) * (2*beta*g48) * weight0;
            gout109 += (g2) * (2*beta*g75) * weight0;
            gout110 += (g2) * (2*beta*g48) * (g99) * weight0;
            gout111 += (g18) * (2*beta*g52) * weight0;
            gout112 += (C00x) * (2*beta*g79) * weight0;
            gout113 += (C00x) * (2*beta*g52) * (g99) * weight0;
            gout114 += (g18) * (2*beta*g48) * (D00z) * weight0;
            gout115 += (C00x) * (2*beta*g75) * (D00z) * weight0;
            gout116 += (C00x) * (2*beta*g48) * (g105) * weight0;
            gout117 += (g22) * (2*beta*g50) * weight0;
            gout118 += (D00x) * (2*beta*g77) * weight0;
            gout119 += (D00x) * (2*beta*g50) * (g99) * weight0;
            gout120 += (g16) * (2*beta*g57) * weight0;
            gout121 += (2*beta*g82) * weight0;
            gout122 += (2*beta*g57) * (g99) * weight0;
            gout123 += (g16) * (2*beta*g50) * (D00z) * weight0;
            gout124 += (2*beta*g77) * (D00z) * weight0;
            gout125 += (2*beta*g50) * (g105) * weight0;
            gout126 += (g22) * (2*beta*g48) * (C00z) * weight0;
            gout127 += (D00x) * (2*beta*g75) * (C00z) * weight0;
            gout128 += (D00x) * (2*beta*g48) * (g101) * weight0;
            gout129 += (g16) * (2*beta*g52) * (C00z) * weight0;
            gout130 += (2*beta*g79) * (C00z) * weight0;
            gout131 += (2*beta*g52) * (g101) * weight0;
            gout132 += (g16) * (2*beta*g48) * (g85) * weight0;
            gout133 += (2*beta*g75) * (g85) * weight0;
            gout134 += (2*beta*g48) * (g111) * weight0;
            gout135 += (g28) * (2*beta*g89) * weight0;
            gout136 += (g2) * (g58) * (2*beta*g89) * weight0;
            gout137 += (g2) * (2*beta*g116) * weight0;
            gout138 += (g18) * (D00y) * (2*beta*g89) * weight0;
            gout139 += (C00x) * (g64) * (2*beta*g89) * weight0;
            gout140 += (C00x) * (D00y) * (2*beta*g116) * weight0;
            gout141 += (g18) * (2*beta*g93) * weight0;
            gout142 += (C00x) * (g58) * (2*beta*g93) * weight0;
            gout143 += (C00x) * (2*beta*g120) * weight0;
            gout144 += (g22) * (C00y) * (2*beta*g89) * weight0;
            gout145 += (D00x) * (g60) * (2*beta*g89) * weight0;
            gout146 += (D00x) * (C00y) * (2*beta*g116) * weight0;
            gout147 += (g16) * (g44) * (2*beta*g89) * weight0;
            gout148 += (g70) * (2*beta*g89) * weight0;
            gout149 += (g44) * (2*beta*g116) * weight0;
            gout150 += (g16) * (C00y) * (2*beta*g93) * weight0;
            gout151 += (g60) * (2*beta*g93) * weight0;
            gout152 += (C00y) * (2*beta*g120) * weight0;
            gout153 += (g22) * (2*beta*g91) * weight0;
            gout154 += (D00x) * (g58) * (2*beta*g91) * weight0;
            gout155 += (D00x) * (2*beta*g118) * weight0;
            gout156 += (g16) * (D00y) * (2*beta*g91) * weight0;
            gout157 += (g64) * (2*beta*g91) * weight0;
            gout158 += (D00y) * (2*beta*g118) * weight0;
            gout159 += (g16) * (2*beta*g98) * weight0;
            gout160 += (g58) * (2*beta*g98) * weight0;
            gout161 += (2*beta*g123) * weight0;
        }
    } }

    int *ao_loc = c_bpcache.ao_loc;
    int i0 = ao_loc[ish];
    int j0 = ao_loc[jsh];
    int k0 = ao_loc[ksh];
    int l0 = ao_loc[lsh];
    int n_dm = jk.n_dm;
    int nao = jk.nao;
    size_t nao2 = nao * nao;
    double* __restrict__ dm = jk.dm;
    double *vj = jk.vj;
    double *vk = jk.vk;
    double d_0, d_1, d_2, d_3, d_4, d_5, d_6, d_7, d_8;

    for (int i_dm = 0; i_dm < n_dm; ++i_dm) {
        if (vj != NULL) {
            d_0 = dm[(k0+0)+nao*(l0+0)];
            d_1 = dm[(k0+0)+nao*(l0+1)];
            d_2 = dm[(k0+0)+nao*(l0+2)];
            d_3 = dm[(k0+1)+nao*(l0+0)];
            d_4 = dm[(k0+1)+nao*(l0+1)];
            d_5 = dm[(k0+1)+nao*(l0+2)];
            d_6 = dm[(k0+2)+nao*(l0+0)];
            d_7 = dm[(k0+2)+nao*(l0+1)];
            d_8 = dm[(k0+2)+nao*(l0+2)];
            atomicAdd(vj+(i0+0)+nao*(j0+0), gout0*d_0+gout1*d_1+gout2*d_2+gout3*d_3+gout4*d_4+gout5*d_5+gout6*d_6+gout7*d_7+gout8*d_8);
            atomicAdd(vj+(i0+1)+nao*(j0+0), gout9*d_0+gout10*d_1+gout11*d_2+gout12*d_3+gout13*d_4+gout14*d_5+gout15*d_6+gout16*d_7+gout17*d_8);
            atomicAdd(vj+(i0+2)+nao*(j0+0), gout18*d_0+gout19*d_1+gout20*d_2+gout21*d_3+gout22*d_4+gout23*d_5+gout24*d_6+gout25*d_7+gout26*d_8);
            atomicAdd(vj+(i0+0)+nao*(j0+0)+nao2, gout27*d_0+gout28*d_1+gout29*d_2+gout30*d_3+gout31*d_4+gout32*d_5+gout33*d_6+gout34*d_7+gout35*d_8);
            atomicAdd(vj+(i0+1)+nao*(j0+0)+nao2, gout36*d_0+gout37*d_1+gout38*d_2+gout39*d_3+gout40*d_4+gout41*d_5+gout42*d_6+gout43*d_7+gout44*d_8);
            atomicAdd(vj+(i0+2)+nao*(j0+0)+nao2, gout45*d_0+gout46*d_1+gout47*d_2+gout48*d_3+gout49*d_4+gout50*d_5+gout51*d_6+gout52*d_7+gout53*d_8);
            atomicAdd(vj+(i0+0)+nao*(j0+0)+2*nao2, gout54*d_0+gout55*d_1+gout56*d_2+gout57*d_3+gout58*d_4+gout59*d_5+gout60*d_6+gout61*d_7+gout62*d_8);
            atomicAdd(vj+(i0+1)+nao*(j0+0)+2*nao2, gout63*d_0+gout64*d_1+gout65*d_2+gout66*d_3+gout67*d_4+gout68*d_5+gout69*d_6+gout70*d_7+gout71*d_8);
            atomicAdd(vj+(i0+2)+nao*(j0+0)+2*nao2, gout72*d_0+gout73*d_1+gout74*d_2+gout75*d_3+gout76*d_4+gout77*d_5+gout78*d_6+gout79*d_7+gout80*d_8);
            atomicAdd(vj+nao*(i0+0)+(j0+0), gout81*d_0+gout82*d_1+gout83*d_2+gout84*d_3+gout85*d_4+gout86*d_5+gout87*d_6+gout88*d_7+gout89*d_8);
            atomicAdd(vj+nao*(i0+1)+(j0+0), gout90*d_0+gout91*d_1+gout92*d_2+gout93*d_3+gout94*d_4+gout95*d_5+gout96*d_6+gout97*d_7+gout98*d_8);
            atomicAdd(vj+nao*(i0+2)+(j0+0), gout99*d_0+gout100*d_1+gout101*d_2+gout102*d_3+gout103*d_4+gout104*d_5+gout105*d_6+gout106*d_7+gout107*d_8);
            atomicAdd(vj+nao*(i0+0)+(j0+0)+nao2, gout108*d_0+gout109*d_1+gout110*d_2+gout111*d_3+gout112*d_4+gout113*d_5+gout114*d_6+gout115*d_7+gout116*d_8);
            atomicAdd(vj+nao*(i0+1)+(j0+0)+nao2, gout117*d_0+gout118*d_1+gout119*d_2+gout120*d_3+gout121*d_4+gout122*d_5+gout123*d_6+gout124*d_7+gout125*d_8);
            atomicAdd(vj+nao*(i0+2)+(j0+0)+nao2, gout126*d_0+gout127*d_1+gout128*d_2+gout129*d_3+gout130*d_4+gout131*d_5+gout132*d_6+gout133*d_7+gout134*d_8);
            atomicAdd(vj+nao*(i0+0)+(j0+0)+2*nao2, gout135*d_0+gout136*d_1+gout137*d_2+gout138*d_3+gout139*d_4+gout140*d_5+gout141*d_6+gout142*d_7+gout143*d_8);
            atomicAdd(vj+nao*(i0+1)+(j0+0)+2*nao2, gout144*d_0+gout145*d_1+gout146*d_2+gout147*d_3+gout148*d_4+gout149*d_5+gout150*d_6+gout151*d_7+gout152*d_8);
            atomicAdd(vj+nao*(i0+2)+(j0+0)+2*nao2, gout153*d_0+gout154*d_1+gout155*d_2+gout156*d_3+gout157*d_4+gout158*d_5+gout159*d_6+gout160*d_7+gout161*d_8);
            vj += 3*nao2;
        }
        if (vk != NULL) {
            // ijkl, jk -> il
            d_0 = dm[(j0+0)+nao*(k0+0)];
            d_1 = dm[(j0+0)+nao*(k0+1)];
            d_2 = dm[(j0+0)+nao*(k0+2)];
            atomicAdd(vk+(i0+0)+nao*(l0+0), gout0*d_0+gout3*d_1+gout6*d_2);
            atomicAdd(vk+(i0+0)+nao*(l0+1), gout1*d_0+gout4*d_1+gout7*d_2);
            atomicAdd(vk+(i0+0)+nao*(l0+2), gout2*d_0+gout5*d_1+gout8*d_2);
            atomicAdd(vk+(i0+1)+nao*(l0+0), gout9*d_0+gout12*d_1+gout15*d_2);
            atomicAdd(vk+(i0+1)+nao*(l0+1), gout10*d_0+gout13*d_1+gout16*d_2);
            atomicAdd(vk+(i0+1)+nao*(l0+2), gout11*d_0+gout14*d_1+gout17*d_2);
            atomicAdd(vk+(i0+2)+nao*(l0+0), gout18*d_0+gout21*d_1+gout24*d_2);
            atomicAdd(vk+(i0+2)+nao*(l0+1), gout19*d_0+gout22*d_1+gout25*d_2);
            atomicAdd(vk+(i0+2)+nao*(l0+2), gout20*d_0+gout23*d_1+gout26*d_2);
            atomicAdd(vk+(i0+0)+nao*(l0+0)+nao2, gout27*d_0+gout30*d_1+gout33*d_2);
            atomicAdd(vk+(i0+0)+nao*(l0+1)+nao2, gout28*d_0+gout31*d_1+gout34*d_2);
            atomicAdd(vk+(i0+0)+nao*(l0+2)+nao2, gout29*d_0+gout32*d_1+gout35*d_2);
            atomicAdd(vk+(i0+1)+nao*(l0+0)+nao2, gout36*d_0+gout39*d_1+gout42*d_2);
            atomicAdd(vk+(i0+1)+nao*(l0+1)+nao2, gout37*d_0+gout40*d_1+gout43*d_2);
            atomicAdd(vk+(i0+1)+nao*(l0+2)+nao2, gout38*d_0+gout41*d_1+gout44*d_2);
            atomicAdd(vk+(i0+2)+nao*(l0+0)+nao2, gout45*d_0+gout48*d_1+gout51*d_2);
            atomicAdd(vk+(i0+2)+nao*(l0+1)+nao2, gout46*d_0+gout49*d_1+gout52*d_2);
            atomicAdd(vk+(i0+2)+nao*(l0+2)+nao2, gout47*d_0+gout50*d_1+gout53*d_2);
            atomicAdd(vk+(i0+0)+nao*(l0+0)+2*nao2, gout54*d_0+gout57*d_1+gout60*d_2);
            atomicAdd(vk+(i0+0)+nao*(l0+1)+2*nao2, gout55*d_0+gout58*d_1+gout61*d_2);
            atomicAdd(vk+(i0+0)+nao*(l0+2)+2*nao2, gout56*d_0+gout59*d_1+gout62*d_2);
            atomicAdd(vk+(i0+1)+nao*(l0+0)+2*nao2, gout63*d_0+gout66*d_1+gout69*d_2);
            atomicAdd(vk+(i0+1)+nao*(l0+1)+2*nao2, gout64*d_0+gout67*d_1+gout70*d_2);
            atomicAdd(vk+(i0+1)+nao*(l0+2)+2*nao2, gout65*d_0+gout68*d_1+gout71*d_2);
            atomicAdd(vk+(i0+2)+nao*(l0+0)+2*nao2, gout72*d_0+gout75*d_1+gout78*d_2);
            atomicAdd(vk+(i0+2)+nao*(l0+1)+2*nao2, gout73*d_0+gout76*d_1+gout79*d_2);
            atomicAdd(vk+(i0+2)+nao*(l0+2)+2*nao2, gout74*d_0+gout77*d_1+gout80*d_2);
            // ijkl, jl -> ik
            d_0 = dm[(j0+0)+nao*(l0+0)];
            d_1 = dm[(j0+0)+nao*(l0+1)];
            d_2 = dm[(j0+0)+nao*(l0+2)];
            atomicAdd(vk+(i0+0)+nao*(k0+0), gout0*d_0+gout1*d_1+gout2*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+1), gout3*d_0+gout4*d_1+gout5*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+2), gout6*d_0+gout7*d_1+gout8*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+0), gout9*d_0+gout10*d_1+gout11*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+1), gout12*d_0+gout13*d_1+gout14*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+2), gout15*d_0+gout16*d_1+gout17*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+0), gout18*d_0+gout19*d_1+gout20*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+1), gout21*d_0+gout22*d_1+gout23*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+2), gout24*d_0+gout25*d_1+gout26*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+0)+nao2, gout27*d_0+gout28*d_1+gout29*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+1)+nao2, gout30*d_0+gout31*d_1+gout32*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+2)+nao2, gout33*d_0+gout34*d_1+gout35*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+0)+nao2, gout36*d_0+gout37*d_1+gout38*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+1)+nao2, gout39*d_0+gout40*d_1+gout41*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+2)+nao2, gout42*d_0+gout43*d_1+gout44*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+0)+nao2, gout45*d_0+gout46*d_1+gout47*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+1)+nao2, gout48*d_0+gout49*d_1+gout50*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+2)+nao2, gout51*d_0+gout52*d_1+gout53*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+0)+2*nao2, gout54*d_0+gout55*d_1+gout56*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+1)+2*nao2, gout57*d_0+gout58*d_1+gout59*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+2)+2*nao2, gout60*d_0+gout61*d_1+gout62*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+0)+2*nao2, gout63*d_0+gout64*d_1+gout65*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+1)+2*nao2, gout66*d_0+gout67*d_1+gout68*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+2)+2*nao2, gout69*d_0+gout70*d_1+gout71*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+0)+2*nao2, gout72*d_0+gout73*d_1+gout74*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+1)+2*nao2, gout75*d_0+gout76*d_1+gout77*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+2)+2*nao2, gout78*d_0+gout79*d_1+gout80*d_2);
            // ijkl, ik -> jl
            d_0 = dm[(i0+0)+nao*(k0+0)];
            d_1 = dm[(i0+0)+nao*(k0+1)];
            d_2 = dm[(i0+0)+nao*(k0+2)];
            d_3 = dm[(i0+1)+nao*(k0+0)];
            d_4 = dm[(i0+1)+nao*(k0+1)];
            d_5 = dm[(i0+1)+nao*(k0+2)];
            d_6 = dm[(i0+2)+nao*(k0+0)];
            d_7 = dm[(i0+2)+nao*(k0+1)];
            d_8 = dm[(i0+2)+nao*(k0+2)];
            atomicAdd(vk+(j0+0)+nao*(l0+0), gout81*d_0+gout84*d_1+gout87*d_2+gout90*d_3+gout93*d_4+gout96*d_5+gout99*d_6+gout102*d_7+gout105*d_8);
            atomicAdd(vk+(j0+0)+nao*(l0+1), gout82*d_0+gout85*d_1+gout88*d_2+gout91*d_3+gout94*d_4+gout97*d_5+gout100*d_6+gout103*d_7+gout106*d_8);
            atomicAdd(vk+(j0+0)+nao*(l0+2), gout83*d_0+gout86*d_1+gout89*d_2+gout92*d_3+gout95*d_4+gout98*d_5+gout101*d_6+gout104*d_7+gout107*d_8);
            atomicAdd(vk+(j0+0)+nao*(l0+0)+nao2, gout108*d_0+gout111*d_1+gout114*d_2+gout117*d_3+gout120*d_4+gout123*d_5+gout126*d_6+gout129*d_7+gout132*d_8);
            atomicAdd(vk+(j0+0)+nao*(l0+1)+nao2, gout109*d_0+gout112*d_1+gout115*d_2+gout118*d_3+gout121*d_4+gout124*d_5+gout127*d_6+gout130*d_7+gout133*d_8);
            atomicAdd(vk+(j0+0)+nao*(l0+2)+nao2, gout110*d_0+gout113*d_1+gout116*d_2+gout119*d_3+gout122*d_4+gout125*d_5+gout128*d_6+gout131*d_7+gout134*d_8);
            atomicAdd(vk+(j0+0)+nao*(l0+0)+2*nao2, gout135*d_0+gout138*d_1+gout141*d_2+gout144*d_3+gout147*d_4+gout150*d_5+gout153*d_6+gout156*d_7+gout159*d_8);
            atomicAdd(vk+(j0+0)+nao*(l0+1)+2*nao2, gout136*d_0+gout139*d_1+gout142*d_2+gout145*d_3+gout148*d_4+gout151*d_5+gout154*d_6+gout157*d_7+gout160*d_8);
            atomicAdd(vk+(j0+0)+nao*(l0+2)+2*nao2, gout137*d_0+gout140*d_1+gout143*d_2+gout146*d_3+gout149*d_4+gout152*d_5+gout155*d_6+gout158*d_7+gout161*d_8);
            // ijkl, il -> jk
            d_0 = dm[(i0+0)+nao*(l0+0)];
            d_1 = dm[(i0+0)+nao*(l0+1)];
            d_2 = dm[(i0+0)+nao*(l0+2)];
            d_3 = dm[(i0+1)+nao*(l0+0)];
            d_4 = dm[(i0+1)+nao*(l0+1)];
            d_5 = dm[(i0+1)+nao*(l0+2)];
            d_6 = dm[(i0+2)+nao*(l0+0)];
            d_7 = dm[(i0+2)+nao*(l0+1)];
            d_8 = dm[(i0+2)+nao*(l0+2)];
            atomicAdd(vk+(j0+0)+nao*(k0+0), gout81*d_0+gout82*d_1+gout83*d_2+gout90*d_3+gout91*d_4+gout92*d_5+gout99*d_6+gout100*d_7+gout101*d_8);
            atomicAdd(vk+(j0+0)+nao*(k0+1), gout84*d_0+gout85*d_1+gout86*d_2+gout93*d_3+gout94*d_4+gout95*d_5+gout102*d_6+gout103*d_7+gout104*d_8);
            atomicAdd(vk+(j0+0)+nao*(k0+2), gout87*d_0+gout88*d_1+gout89*d_2+gout96*d_3+gout97*d_4+gout98*d_5+gout105*d_6+gout106*d_7+gout107*d_8);
            atomicAdd(vk+(j0+0)+nao*(k0+0)+nao2, gout108*d_0+gout109*d_1+gout110*d_2+gout117*d_3+gout118*d_4+gout119*d_5+gout126*d_6+gout127*d_7+gout128*d_8);
            atomicAdd(vk+(j0+0)+nao*(k0+1)+nao2, gout111*d_0+gout112*d_1+gout113*d_2+gout120*d_3+gout121*d_4+gout122*d_5+gout129*d_6+gout130*d_7+gout131*d_8);
            atomicAdd(vk+(j0+0)+nao*(k0+2)+nao2, gout114*d_0+gout115*d_1+gout116*d_2+gout123*d_3+gout124*d_4+gout125*d_5+gout132*d_6+gout133*d_7+gout134*d_8);
            atomicAdd(vk+(j0+0)+nao*(k0+0)+2*nao2, gout135*d_0+gout136*d_1+gout137*d_2+gout144*d_3+gout145*d_4+gout146*d_5+gout153*d_6+gout154*d_7+gout155*d_8);
            atomicAdd(vk+(j0+0)+nao*(k0+1)+2*nao2, gout138*d_0+gout139*d_1+gout140*d_2+gout147*d_3+gout148*d_4+gout149*d_5+gout156*d_6+gout157*d_7+gout158*d_8);
            atomicAdd(vk+(j0+0)+nao*(k0+2)+2*nao2, gout141*d_0+gout142*d_1+gout143*d_2+gout150*d_3+gout151*d_4+gout152*d_5+gout159*d_6+gout160*d_7+gout161*d_8);
            vk += 3*nao2;
        }
        dm += nao2;
    }
}

__global__
static void GINTint2e_ip1_jk_kernel_1020(GINTEnvVars envs, JKMatrix jk,
                                    BasisProdOffsets offsets)
{
    int ntasks_ij = offsets.ntasks_ij;
    int ntasks_kl = offsets.ntasks_kl;
    int task_ij = blockIdx.x * blockDim.x + threadIdx.x;
    int task_kl = blockIdx.y * blockDim.y + threadIdx.y;
    if (task_ij >= ntasks_ij || task_kl >= ntasks_kl) {
        return;
    }
    int bas_ij = offsets.bas_ij + task_ij;
    int bas_kl = offsets.bas_kl + task_kl;
    double norm = envs.fac;
    double omega = envs.omega;
    int *bas_pair2bra = c_bpcache.bas_pair2bra;
    int *bas_pair2ket = c_bpcache.bas_pair2ket;
    int ish = bas_pair2bra[bas_ij];
    int jsh = bas_pair2ket[bas_ij];
    int ksh = bas_pair2bra[bas_kl];
    int lsh = bas_pair2ket[bas_kl];
    int nprim_ij = envs.nprim_ij;
    int nprim_kl = envs.nprim_kl;
    int prim_ij = offsets.primitive_ij + task_ij * nprim_ij;
    int prim_kl = offsets.primitive_kl + task_kl * nprim_kl;

    double* __restrict__ a12 = c_bpcache.a12;
    double* __restrict__ e12 = c_bpcache.e12;
    double* __restrict__ x12 = c_bpcache.x12;
    double* __restrict__ y12 = c_bpcache.y12;
    double* __restrict__ z12 = c_bpcache.z12;
    double * __restrict__ i_exponent = c_bpcache.a1;
    double * __restrict__ j_exponent = c_bpcache.a2;

    int ij, kl;
    int prim_ij0, prim_ij1, prim_kl0, prim_kl1;
    int nbas = c_bpcache.nbas;
    double* __restrict__ bas_x = c_bpcache.bas_coords;
    double* __restrict__ bas_y = bas_x + nbas;
    double* __restrict__ bas_z = bas_y + nbas;

    double gout0 = 0;
    double gout1 = 0;
    double gout2 = 0;
    double gout3 = 0;
    double gout4 = 0;
    double gout5 = 0;
    double gout6 = 0;
    double gout7 = 0;
    double gout8 = 0;
    double gout9 = 0;
    double gout10 = 0;
    double gout11 = 0;
    double gout12 = 0;
    double gout13 = 0;
    double gout14 = 0;
    double gout15 = 0;
    double gout16 = 0;
    double gout17 = 0;
    double gout18 = 0;
    double gout19 = 0;
    double gout20 = 0;
    double gout21 = 0;
    double gout22 = 0;
    double gout23 = 0;
    double gout24 = 0;
    double gout25 = 0;
    double gout26 = 0;
    double gout27 = 0;
    double gout28 = 0;
    double gout29 = 0;
    double gout30 = 0;
    double gout31 = 0;
    double gout32 = 0;
    double gout33 = 0;
    double gout34 = 0;
    double gout35 = 0;
    double gout36 = 0;
    double gout37 = 0;
    double gout38 = 0;
    double gout39 = 0;
    double gout40 = 0;
    double gout41 = 0;
    double gout42 = 0;
    double gout43 = 0;
    double gout44 = 0;
    double gout45 = 0;
    double gout46 = 0;
    double gout47 = 0;
    double gout48 = 0;
    double gout49 = 0;
    double gout50 = 0;
    double gout51 = 0;
    double gout52 = 0;
    double gout53 = 0;
    double gout54 = 0;
    double gout55 = 0;
    double gout56 = 0;
    double gout57 = 0;
    double gout58 = 0;
    double gout59 = 0;
    double gout60 = 0;
    double gout61 = 0;
    double gout62 = 0;
    double gout63 = 0;
    double gout64 = 0;
    double gout65 = 0;
    double gout66 = 0;
    double gout67 = 0;
    double gout68 = 0;
    double gout69 = 0;
    double gout70 = 0;
    double gout71 = 0;
    double gout72 = 0;
    double gout73 = 0;
    double gout74 = 0;
    double gout75 = 0;
    double gout76 = 0;
    double gout77 = 0;
    double gout78 = 0;
    double gout79 = 0;
    double gout80 = 0;
    double gout81 = 0;
    double gout82 = 0;
    double gout83 = 0;
    double gout84 = 0;
    double gout85 = 0;
    double gout86 = 0;
    double gout87 = 0;
    double gout88 = 0;
    double gout89 = 0;
    double gout90 = 0;
    double gout91 = 0;
    double gout92 = 0;
    double gout93 = 0;
    double gout94 = 0;
    double gout95 = 0;
    double gout96 = 0;
    double gout97 = 0;
    double gout98 = 0;
    double gout99 = 0;
    double gout100 = 0;
    double gout101 = 0;
    double gout102 = 0;
    double gout103 = 0;
    double gout104 = 0;
    double gout105 = 0;
    double gout106 = 0;
    double gout107 = 0;

    double xi = bas_x[ish];
    double yi = bas_y[ish];
    double zi = bas_z[ish];
    double ABx = xi - bas_x[jsh];
    double ABy = yi - bas_y[jsh];
    double ABz = zi - bas_z[jsh];
    double xk = bas_x[ksh];
    double yk = bas_y[ksh];
    double zk = bas_z[ksh];

    prim_ij0 = prim_ij;
    prim_ij1 = prim_ij + nprim_ij;
    prim_kl0 = prim_kl;
    prim_kl1 = prim_kl + nprim_kl;
    double rw[6];
    int irys;
    for (ij = prim_ij0; ij < prim_ij1; ++ij) {
        double alpha = i_exponent[ij];
        double beta = j_exponent[ij];
        double aij = a12[ij];
        double eij = e12[ij];
        double xij = x12[ij];
        double yij = y12[ij];
        double zij = z12[ij];
    for (kl = prim_kl0; kl < prim_kl1; ++kl) {
        double akl = a12[kl];
        double ekl = e12[kl];
        double xkl = x12[kl];
        double ykl = y12[kl];
        double zkl = z12[kl];
        double xijxkl = xij - xkl;
        double yijykl = yij - ykl;
        double zijzkl = zij - zkl;
        double aijkl = aij + akl;
        double a1 = aij * akl;
        double a0 = a1 / aijkl;
        double theta = omega > 0.0 ? omega * omega / (omega * omega + a0) : 1.0; 
        a0 *= theta;
        double x = a0 * (xijxkl * xijxkl + yijykl * yijykl + zijzkl * zijzkl);
        double fac = norm * eij * ekl * sqrt(a0 / (a1 * a1 * a1));
        //double fac = norm * eij * ekl / (sqrt(aijkl) * a1);

        GINTrys_root<3>(x, rw);
        GINTscale_u<3>(rw, theta);
      for (irys = 0; irys < 3; ++irys) {
            double weight0 = rw[irys+3] * fac;
            double root0 = rw[irys];
            double u2 = a0 * root0;
            double tmp4 = .5 / (u2 * aijkl + a1);
            double B00 = u2 * tmp4;
            double tmp1 = 2 * B00;
            double B10 = B00 + tmp4 * akl;
            double tmp2 = tmp1 * akl;
            double C00x = xij - xi - tmp2 * xijxkl;
            double C00y = yij - yi - tmp2 * yijykl;
            double C00z = zij - zi - tmp2 * zijzkl;
            double B01 = B00 + tmp4 * aij;
            double tmp3 = tmp1 * aij;
            double D00x = xkl - xk + tmp3 * xijxkl;
            double D00y = ykl - yk + tmp3 * yijykl;
            double D00z = zkl - zk + tmp3 * zijzkl;

            double g0 = B10+C00x*C00x;
            double g1 = C00x*D00x;
            double g2 = B00+g1;
            double g3 = 2*B00*C00x;
            double g4 = g0*D00x;
            double g5 = g3+g4;
            double g6 = B01+D00x*D00x;
            double g7 = 2*B00*D00x;
            double g8 = C00x*g6;
            double g9 = g7+g8;
            double g10 = 2*B00*B00;
            double g13 = g10+(4*B00*C00x*D00x)+(g0*g6);
            double g14 = ABx+C00x;
            double g16 = B10+(C00x*g14);
            double g18 = B00+(g14*D00x);
            double g20 = ABx+(2*C00x);
            double g23 = (B00*g20)+(g16*D00x);
            double g25 = g7+(g14*g6);
            double g28 = g10+(2*B00*g20*D00x)+(g16*g6);
            double g29 = B10+C00y*C00y;
            double g31 = B00+(C00y*D00y);
            double g34 = (2*B00*C00y)+(g29*D00y);
            double g35 = B01+D00y*D00y;
            double g36 = 2*B00*D00y;
            double g38 = g36+(C00y*g35);
            double g41 = g10+(4*B00*C00y*D00y)+(g29*g35);
            double g42 = ABy+C00y;
            double g44 = B10+(C00y*g42);
            double g46 = B00+(g42*D00y);
            double g48 = ABy+(2*C00y);
            double g51 = (B00*g48)+(g44*D00y);
            double g53 = g36+(g42*g35);
            double g56 = g10+(2*B00*g48*D00y)+(g44*g35);
            double g57 = B10+C00z*C00z;
            double g59 = B00+(C00z*D00z);
            double g62 = (2*B00*C00z)+(g57*D00z);
            double g63 = B01+D00z*D00z;
            double g64 = 2*B00*D00z;
            double g66 = g64+(C00z*g63);
            double g69 = g10+(4*B00*C00z*D00z)+(g57*g63);
            double g70 = ABz+C00z;
            double g72 = B10+(C00z*g70);
            double g74 = B00+(g70*D00z);
            double g76 = ABz+(2*C00z);
            double g79 = (B00*g76)+(g72*D00z);
            double g81 = g64+(g70*g63);
            double g84 = g10+(2*B00*g76*D00z)+(g72*g63);

            gout0 += (-g6 + 2*alpha*g13) * weight0;
            gout1 += (-D00x + 2*alpha*g5) * (D00y) * weight0;
            gout2 += (-D00x + 2*alpha*g5) * (D00z) * weight0;
            gout3 += (-1 + 2*alpha*g0) * (g35) * weight0;
            gout4 += (-1 + 2*alpha*g0) * (D00y) * (D00z) * weight0;
            gout5 += (-1 + 2*alpha*g0) * (g63) * weight0;
            gout6 += (2*alpha*g9) * (C00y) * weight0;
            gout7 += (2*alpha*g2) * (g31) * weight0;
            gout8 += (2*alpha*g2) * (C00y) * (D00z) * weight0;
            gout9 += (2*alpha*C00x) * (g38) * weight0;
            gout10 += (2*alpha*C00x) * (g31) * (D00z) * weight0;
            gout11 += (2*alpha*C00x) * (C00y) * (g63) * weight0;
            gout12 += (2*alpha*g9) * (C00z) * weight0;
            gout13 += (2*alpha*g2) * (D00y) * (C00z) * weight0;
            gout14 += (2*alpha*g2) * (g59) * weight0;
            gout15 += (2*alpha*C00x) * (g35) * (C00z) * weight0;
            gout16 += (2*alpha*C00x) * (D00y) * (g59) * weight0;
            gout17 += (2*alpha*C00x) * (g66) * weight0;
            gout18 += (g9) * (2*alpha*C00y) * weight0;
            gout19 += (g2) * (2*alpha*g31) * weight0;
            gout20 += (g2) * (2*alpha*C00y) * (D00z) * weight0;
            gout21 += (C00x) * (2*alpha*g38) * weight0;
            gout22 += (C00x) * (2*alpha*g31) * (D00z) * weight0;
            gout23 += (C00x) * (2*alpha*C00y) * (g63) * weight0;
            gout24 += (g6) * (-1 + 2*alpha*g29) * weight0;
            gout25 += (D00x) * (-D00y + 2*alpha*g34) * weight0;
            gout26 += (D00x) * (-1 + 2*alpha*g29) * (D00z) * weight0;
            gout27 += (-g35 + 2*alpha*g41) * weight0;
            gout28 += (-D00y + 2*alpha*g34) * (D00z) * weight0;
            gout29 += (-1 + 2*alpha*g29) * (g63) * weight0;
            gout30 += (g6) * (2*alpha*C00y) * (C00z) * weight0;
            gout31 += (D00x) * (2*alpha*g31) * (C00z) * weight0;
            gout32 += (D00x) * (2*alpha*C00y) * (g59) * weight0;
            gout33 += (2*alpha*g38) * (C00z) * weight0;
            gout34 += (2*alpha*g31) * (g59) * weight0;
            gout35 += (2*alpha*C00y) * (g66) * weight0;
            gout36 += (g9) * (2*alpha*C00z) * weight0;
            gout37 += (g2) * (D00y) * (2*alpha*C00z) * weight0;
            gout38 += (g2) * (2*alpha*g59) * weight0;
            gout39 += (C00x) * (g35) * (2*alpha*C00z) * weight0;
            gout40 += (C00x) * (D00y) * (2*alpha*g59) * weight0;
            gout41 += (C00x) * (2*alpha*g66) * weight0;
            gout42 += (g6) * (C00y) * (2*alpha*C00z) * weight0;
            gout43 += (D00x) * (g31) * (2*alpha*C00z) * weight0;
            gout44 += (D00x) * (C00y) * (2*alpha*g59) * weight0;
            gout45 += (g38) * (2*alpha*C00z) * weight0;
            gout46 += (g31) * (2*alpha*g59) * weight0;
            gout47 += (C00y) * (2*alpha*g66) * weight0;
            gout48 += (g6) * (-1 + 2*alpha*g57) * weight0;
            gout49 += (D00x) * (D00y) * (-1 + 2*alpha*g57) * weight0;
            gout50 += (D00x) * (-D00z + 2*alpha*g62) * weight0;
            gout51 += (g35) * (-1 + 2*alpha*g57) * weight0;
            gout52 += (D00y) * (-D00z + 2*alpha*g62) * weight0;
            gout53 += (-g63 + 2*alpha*g69) * weight0;
            gout54 += (2*beta*g28) * weight0;
            gout55 += (2*beta*g23) * (D00y) * weight0;
            gout56 += (2*beta*g23) * (D00z) * weight0;
            gout57 += (2*beta*g16) * (g35) * weight0;
            gout58 += (2*beta*g16) * (D00y) * (D00z) * weight0;
            gout59 += (2*beta*g16) * (g63) * weight0;
            gout60 += (2*beta*g25) * (C00y) * weight0;
            gout61 += (2*beta*g18) * (g31) * weight0;
            gout62 += (2*beta*g18) * (C00y) * (D00z) * weight0;
            gout63 += (2*beta*g14) * (g38) * weight0;
            gout64 += (2*beta*g14) * (g31) * (D00z) * weight0;
            gout65 += (2*beta*g14) * (C00y) * (g63) * weight0;
            gout66 += (2*beta*g25) * (C00z) * weight0;
            gout67 += (2*beta*g18) * (D00y) * (C00z) * weight0;
            gout68 += (2*beta*g18) * (g59) * weight0;
            gout69 += (2*beta*g14) * (g35) * (C00z) * weight0;
            gout70 += (2*beta*g14) * (D00y) * (g59) * weight0;
            gout71 += (2*beta*g14) * (g66) * weight0;
            gout72 += (g9) * (2*beta*g42) * weight0;
            gout73 += (g2) * (2*beta*g46) * weight0;
            gout74 += (g2) * (2*beta*g42) * (D00z) * weight0;
            gout75 += (C00x) * (2*beta*g53) * weight0;
            gout76 += (C00x) * (2*beta*g46) * (D00z) * weight0;
            gout77 += (C00x) * (2*beta*g42) * (g63) * weight0;
            gout78 += (g6) * (2*beta*g44) * weight0;
            gout79 += (D00x) * (2*beta*g51) * weight0;
            gout80 += (D00x) * (2*beta*g44) * (D00z) * weight0;
            gout81 += (2*beta*g56) * weight0;
            gout82 += (2*beta*g51) * (D00z) * weight0;
            gout83 += (2*beta*g44) * (g63) * weight0;
            gout84 += (g6) * (2*beta*g42) * (C00z) * weight0;
            gout85 += (D00x) * (2*beta*g46) * (C00z) * weight0;
            gout86 += (D00x) * (2*beta*g42) * (g59) * weight0;
            gout87 += (2*beta*g53) * (C00z) * weight0;
            gout88 += (2*beta*g46) * (g59) * weight0;
            gout89 += (2*beta*g42) * (g66) * weight0;
            gout90 += (g9) * (2*beta*g70) * weight0;
            gout91 += (g2) * (D00y) * (2*beta*g70) * weight0;
            gout92 += (g2) * (2*beta*g74) * weight0;
            gout93 += (C00x) * (g35) * (2*beta*g70) * weight0;
            gout94 += (C00x) * (D00y) * (2*beta*g74) * weight0;
            gout95 += (C00x) * (2*beta*g81) * weight0;
            gout96 += (g6) * (C00y) * (2*beta*g70) * weight0;
            gout97 += (D00x) * (g31) * (2*beta*g70) * weight0;
            gout98 += (D00x) * (C00y) * (2*beta*g74) * weight0;
            gout99 += (g38) * (2*beta*g70) * weight0;
            gout100 += (g31) * (2*beta*g74) * weight0;
            gout101 += (C00y) * (2*beta*g81) * weight0;
            gout102 += (g6) * (2*beta*g72) * weight0;
            gout103 += (D00x) * (D00y) * (2*beta*g72) * weight0;
            gout104 += (D00x) * (2*beta*g79) * weight0;
            gout105 += (g35) * (2*beta*g72) * weight0;
            gout106 += (D00y) * (2*beta*g79) * weight0;
            gout107 += (2*beta*g84) * weight0;
        }
    } }

    int *ao_loc = c_bpcache.ao_loc;
    int i0 = ao_loc[ish];
    int j0 = ao_loc[jsh];
    int k0 = ao_loc[ksh];
    int l0 = ao_loc[lsh];
    int n_dm = jk.n_dm;
    int nao = jk.nao;
    size_t nao2 = nao * nao;
    double* __restrict__ dm = jk.dm;
    double *vj = jk.vj;
    double *vk = jk.vk;
    double d_0, d_1, d_2, d_3, d_4, d_5, d_6, d_7, d_8, d_9, d_10, d_11, d_12, d_13, d_14, d_15, d_16, d_17;

    for (int i_dm = 0; i_dm < n_dm; ++i_dm) {
        if (vj != NULL) {
            d_0 = dm[(k0+0)+nao*(l0+0)];
            d_1 = dm[(k0+1)+nao*(l0+0)];
            d_2 = dm[(k0+2)+nao*(l0+0)];
            d_3 = dm[(k0+3)+nao*(l0+0)];
            d_4 = dm[(k0+4)+nao*(l0+0)];
            d_5 = dm[(k0+5)+nao*(l0+0)];
            atomicAdd(vj+(i0+0)+nao*(j0+0), gout0*d_0+gout1*d_1+gout2*d_2+gout3*d_3+gout4*d_4+gout5*d_5);
            atomicAdd(vj+(i0+1)+nao*(j0+0), gout6*d_0+gout7*d_1+gout8*d_2+gout9*d_3+gout10*d_4+gout11*d_5);
            atomicAdd(vj+(i0+2)+nao*(j0+0), gout12*d_0+gout13*d_1+gout14*d_2+gout15*d_3+gout16*d_4+gout17*d_5);
            atomicAdd(vj+(i0+0)+nao*(j0+0)+nao2, gout18*d_0+gout19*d_1+gout20*d_2+gout21*d_3+gout22*d_4+gout23*d_5);
            atomicAdd(vj+(i0+1)+nao*(j0+0)+nao2, gout24*d_0+gout25*d_1+gout26*d_2+gout27*d_3+gout28*d_4+gout29*d_5);
            atomicAdd(vj+(i0+2)+nao*(j0+0)+nao2, gout30*d_0+gout31*d_1+gout32*d_2+gout33*d_3+gout34*d_4+gout35*d_5);
            atomicAdd(vj+(i0+0)+nao*(j0+0)+2*nao2, gout36*d_0+gout37*d_1+gout38*d_2+gout39*d_3+gout40*d_4+gout41*d_5);
            atomicAdd(vj+(i0+1)+nao*(j0+0)+2*nao2, gout42*d_0+gout43*d_1+gout44*d_2+gout45*d_3+gout46*d_4+gout47*d_5);
            atomicAdd(vj+(i0+2)+nao*(j0+0)+2*nao2, gout48*d_0+gout49*d_1+gout50*d_2+gout51*d_3+gout52*d_4+gout53*d_5);
            atomicAdd(vj+nao*(i0+0)+(j0+0), gout54*d_0+gout55*d_1+gout56*d_2+gout57*d_3+gout58*d_4+gout59*d_5);
            atomicAdd(vj+nao*(i0+1)+(j0+0), gout60*d_0+gout61*d_1+gout62*d_2+gout63*d_3+gout64*d_4+gout65*d_5);
            atomicAdd(vj+nao*(i0+2)+(j0+0), gout66*d_0+gout67*d_1+gout68*d_2+gout69*d_3+gout70*d_4+gout71*d_5);
            atomicAdd(vj+nao*(i0+0)+(j0+0)+nao2, gout72*d_0+gout73*d_1+gout74*d_2+gout75*d_3+gout76*d_4+gout77*d_5);
            atomicAdd(vj+nao*(i0+1)+(j0+0)+nao2, gout78*d_0+gout79*d_1+gout80*d_2+gout81*d_3+gout82*d_4+gout83*d_5);
            atomicAdd(vj+nao*(i0+2)+(j0+0)+nao2, gout84*d_0+gout85*d_1+gout86*d_2+gout87*d_3+gout88*d_4+gout89*d_5);
            atomicAdd(vj+nao*(i0+0)+(j0+0)+2*nao2, gout90*d_0+gout91*d_1+gout92*d_2+gout93*d_3+gout94*d_4+gout95*d_5);
            atomicAdd(vj+nao*(i0+1)+(j0+0)+2*nao2, gout96*d_0+gout97*d_1+gout98*d_2+gout99*d_3+gout100*d_4+gout101*d_5);
            atomicAdd(vj+nao*(i0+2)+(j0+0)+2*nao2, gout102*d_0+gout103*d_1+gout104*d_2+gout105*d_3+gout106*d_4+gout107*d_5);
            vj += 3*nao2;
        }
        if (vk != NULL) {
            // ijkl, jk -> il
            d_0 = dm[(j0+0)+nao*(k0+0)];
            d_1 = dm[(j0+0)+nao*(k0+1)];
            d_2 = dm[(j0+0)+nao*(k0+2)];
            d_3 = dm[(j0+0)+nao*(k0+3)];
            d_4 = dm[(j0+0)+nao*(k0+4)];
            d_5 = dm[(j0+0)+nao*(k0+5)];
            atomicAdd(vk+(i0+0)+nao*(l0+0), gout0*d_0+gout1*d_1+gout2*d_2+gout3*d_3+gout4*d_4+gout5*d_5);
            atomicAdd(vk+(i0+1)+nao*(l0+0), gout6*d_0+gout7*d_1+gout8*d_2+gout9*d_3+gout10*d_4+gout11*d_5);
            atomicAdd(vk+(i0+2)+nao*(l0+0), gout12*d_0+gout13*d_1+gout14*d_2+gout15*d_3+gout16*d_4+gout17*d_5);
            atomicAdd(vk+(i0+0)+nao*(l0+0)+nao2, gout18*d_0+gout19*d_1+gout20*d_2+gout21*d_3+gout22*d_4+gout23*d_5);
            atomicAdd(vk+(i0+1)+nao*(l0+0)+nao2, gout24*d_0+gout25*d_1+gout26*d_2+gout27*d_3+gout28*d_4+gout29*d_5);
            atomicAdd(vk+(i0+2)+nao*(l0+0)+nao2, gout30*d_0+gout31*d_1+gout32*d_2+gout33*d_3+gout34*d_4+gout35*d_5);
            atomicAdd(vk+(i0+0)+nao*(l0+0)+2*nao2, gout36*d_0+gout37*d_1+gout38*d_2+gout39*d_3+gout40*d_4+gout41*d_5);
            atomicAdd(vk+(i0+1)+nao*(l0+0)+2*nao2, gout42*d_0+gout43*d_1+gout44*d_2+gout45*d_3+gout46*d_4+gout47*d_5);
            atomicAdd(vk+(i0+2)+nao*(l0+0)+2*nao2, gout48*d_0+gout49*d_1+gout50*d_2+gout51*d_3+gout52*d_4+gout53*d_5);
            // ijkl, jl -> ik
            d_0 = dm[(j0+0)+nao*(l0+0)];
            atomicAdd(vk+(i0+0)+nao*(k0+0), gout0*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+1), gout1*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+2), gout2*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+3), gout3*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+4), gout4*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+5), gout5*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+0), gout6*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+1), gout7*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+2), gout8*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+3), gout9*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+4), gout10*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+5), gout11*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+0), gout12*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+1), gout13*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+2), gout14*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+3), gout15*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+4), gout16*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+5), gout17*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+0)+nao2, gout18*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+1)+nao2, gout19*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+2)+nao2, gout20*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+3)+nao2, gout21*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+4)+nao2, gout22*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+5)+nao2, gout23*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+0)+nao2, gout24*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+1)+nao2, gout25*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+2)+nao2, gout26*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+3)+nao2, gout27*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+4)+nao2, gout28*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+5)+nao2, gout29*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+0)+nao2, gout30*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+1)+nao2, gout31*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+2)+nao2, gout32*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+3)+nao2, gout33*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+4)+nao2, gout34*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+5)+nao2, gout35*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+0)+2*nao2, gout36*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+1)+2*nao2, gout37*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+2)+2*nao2, gout38*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+3)+2*nao2, gout39*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+4)+2*nao2, gout40*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+5)+2*nao2, gout41*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+0)+2*nao2, gout42*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+1)+2*nao2, gout43*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+2)+2*nao2, gout44*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+3)+2*nao2, gout45*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+4)+2*nao2, gout46*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+5)+2*nao2, gout47*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+0)+2*nao2, gout48*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+1)+2*nao2, gout49*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+2)+2*nao2, gout50*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+3)+2*nao2, gout51*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+4)+2*nao2, gout52*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+5)+2*nao2, gout53*d_0);
            // ijkl, ik -> jl
            d_0 = dm[(i0+0)+nao*(k0+0)];
            d_1 = dm[(i0+0)+nao*(k0+1)];
            d_2 = dm[(i0+0)+nao*(k0+2)];
            d_3 = dm[(i0+0)+nao*(k0+3)];
            d_4 = dm[(i0+0)+nao*(k0+4)];
            d_5 = dm[(i0+0)+nao*(k0+5)];
            d_6 = dm[(i0+1)+nao*(k0+0)];
            d_7 = dm[(i0+1)+nao*(k0+1)];
            d_8 = dm[(i0+1)+nao*(k0+2)];
            d_9 = dm[(i0+1)+nao*(k0+3)];
            d_10 = dm[(i0+1)+nao*(k0+4)];
            d_11 = dm[(i0+1)+nao*(k0+5)];
            d_12 = dm[(i0+2)+nao*(k0+0)];
            d_13 = dm[(i0+2)+nao*(k0+1)];
            d_14 = dm[(i0+2)+nao*(k0+2)];
            d_15 = dm[(i0+2)+nao*(k0+3)];
            d_16 = dm[(i0+2)+nao*(k0+4)];
            d_17 = dm[(i0+2)+nao*(k0+5)];
            atomicAdd(vk+(j0+0)+nao*(l0+0), gout54*d_0+gout55*d_1+gout56*d_2+gout57*d_3+gout58*d_4+gout59*d_5+gout60*d_6+gout61*d_7+gout62*d_8+gout63*d_9+gout64*d_10+gout65*d_11+gout66*d_12+gout67*d_13+gout68*d_14+gout69*d_15+gout70*d_16+gout71*d_17);
            atomicAdd(vk+(j0+0)+nao*(l0+0)+nao2, gout72*d_0+gout73*d_1+gout74*d_2+gout75*d_3+gout76*d_4+gout77*d_5+gout78*d_6+gout79*d_7+gout80*d_8+gout81*d_9+gout82*d_10+gout83*d_11+gout84*d_12+gout85*d_13+gout86*d_14+gout87*d_15+gout88*d_16+gout89*d_17);
            atomicAdd(vk+(j0+0)+nao*(l0+0)+2*nao2, gout90*d_0+gout91*d_1+gout92*d_2+gout93*d_3+gout94*d_4+gout95*d_5+gout96*d_6+gout97*d_7+gout98*d_8+gout99*d_9+gout100*d_10+gout101*d_11+gout102*d_12+gout103*d_13+gout104*d_14+gout105*d_15+gout106*d_16+gout107*d_17);
            // ijkl, il -> jk
            d_0 = dm[(i0+0)+nao*(l0+0)];
            d_1 = dm[(i0+1)+nao*(l0+0)];
            d_2 = dm[(i0+2)+nao*(l0+0)];
            atomicAdd(vk+(j0+0)+nao*(k0+0), gout54*d_0+gout60*d_1+gout66*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+1), gout55*d_0+gout61*d_1+gout67*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+2), gout56*d_0+gout62*d_1+gout68*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+3), gout57*d_0+gout63*d_1+gout69*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+4), gout58*d_0+gout64*d_1+gout70*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+5), gout59*d_0+gout65*d_1+gout71*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+0)+nao2, gout72*d_0+gout78*d_1+gout84*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+1)+nao2, gout73*d_0+gout79*d_1+gout85*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+2)+nao2, gout74*d_0+gout80*d_1+gout86*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+3)+nao2, gout75*d_0+gout81*d_1+gout87*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+4)+nao2, gout76*d_0+gout82*d_1+gout88*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+5)+nao2, gout77*d_0+gout83*d_1+gout89*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+0)+2*nao2, gout90*d_0+gout96*d_1+gout102*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+1)+2*nao2, gout91*d_0+gout97*d_1+gout103*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+2)+2*nao2, gout92*d_0+gout98*d_1+gout104*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+3)+2*nao2, gout93*d_0+gout99*d_1+gout105*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+4)+2*nao2, gout94*d_0+gout100*d_1+gout106*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+5)+2*nao2, gout95*d_0+gout101*d_1+gout107*d_2);
            vk += 3*nao2;
        }
        dm += nao2;
    }
}

__global__
static void GINTint2e_ip1_jk_kernel_1021(GINTEnvVars envs, JKMatrix jk,
                                    BasisProdOffsets offsets)
{
    int ntasks_ij = offsets.ntasks_ij;
    int ntasks_kl = offsets.ntasks_kl;
    int task_ij = blockIdx.x * blockDim.x + threadIdx.x;
    int task_kl = blockIdx.y * blockDim.y + threadIdx.y;
    if (task_ij >= ntasks_ij || task_kl >= ntasks_kl) {
        return;
    }
    int bas_ij = offsets.bas_ij + task_ij;
    int bas_kl = offsets.bas_kl + task_kl;
    double norm = envs.fac;
    double omega = envs.omega;
    int *bas_pair2bra = c_bpcache.bas_pair2bra;
    int *bas_pair2ket = c_bpcache.bas_pair2ket;
    int ish = bas_pair2bra[bas_ij];
    int jsh = bas_pair2ket[bas_ij];
    int ksh = bas_pair2bra[bas_kl];
    int lsh = bas_pair2ket[bas_kl];
    int nprim_ij = envs.nprim_ij;
    int nprim_kl = envs.nprim_kl;
    int prim_ij = offsets.primitive_ij + task_ij * nprim_ij;
    int prim_kl = offsets.primitive_kl + task_kl * nprim_kl;

    double* __restrict__ a12 = c_bpcache.a12;
    double* __restrict__ e12 = c_bpcache.e12;
    double* __restrict__ x12 = c_bpcache.x12;
    double* __restrict__ y12 = c_bpcache.y12;
    double* __restrict__ z12 = c_bpcache.z12;
    double * __restrict__ i_exponent = c_bpcache.a1;
    double * __restrict__ j_exponent = c_bpcache.a2;

    int ij, kl;
    int prim_ij0, prim_ij1, prim_kl0, prim_kl1;
    int nbas = c_bpcache.nbas;
    double* __restrict__ bas_x = c_bpcache.bas_coords;
    double* __restrict__ bas_y = bas_x + nbas;
    double* __restrict__ bas_z = bas_y + nbas;

    double gout0 = 0;
    double gout1 = 0;
    double gout2 = 0;
    double gout3 = 0;
    double gout4 = 0;
    double gout5 = 0;
    double gout6 = 0;
    double gout7 = 0;
    double gout8 = 0;
    double gout9 = 0;
    double gout10 = 0;
    double gout11 = 0;
    double gout12 = 0;
    double gout13 = 0;
    double gout14 = 0;
    double gout15 = 0;
    double gout16 = 0;
    double gout17 = 0;
    double gout18 = 0;
    double gout19 = 0;
    double gout20 = 0;
    double gout21 = 0;
    double gout22 = 0;
    double gout23 = 0;
    double gout24 = 0;
    double gout25 = 0;
    double gout26 = 0;
    double gout27 = 0;
    double gout28 = 0;
    double gout29 = 0;
    double gout30 = 0;
    double gout31 = 0;
    double gout32 = 0;
    double gout33 = 0;
    double gout34 = 0;
    double gout35 = 0;
    double gout36 = 0;
    double gout37 = 0;
    double gout38 = 0;
    double gout39 = 0;
    double gout40 = 0;
    double gout41 = 0;
    double gout42 = 0;
    double gout43 = 0;
    double gout44 = 0;
    double gout45 = 0;
    double gout46 = 0;
    double gout47 = 0;
    double gout48 = 0;
    double gout49 = 0;
    double gout50 = 0;
    double gout51 = 0;
    double gout52 = 0;
    double gout53 = 0;
    double gout54 = 0;
    double gout55 = 0;
    double gout56 = 0;
    double gout57 = 0;
    double gout58 = 0;
    double gout59 = 0;
    double gout60 = 0;
    double gout61 = 0;
    double gout62 = 0;
    double gout63 = 0;
    double gout64 = 0;
    double gout65 = 0;
    double gout66 = 0;
    double gout67 = 0;
    double gout68 = 0;
    double gout69 = 0;
    double gout70 = 0;
    double gout71 = 0;
    double gout72 = 0;
    double gout73 = 0;
    double gout74 = 0;
    double gout75 = 0;
    double gout76 = 0;
    double gout77 = 0;
    double gout78 = 0;
    double gout79 = 0;
    double gout80 = 0;
    double gout81 = 0;
    double gout82 = 0;
    double gout83 = 0;
    double gout84 = 0;
    double gout85 = 0;
    double gout86 = 0;
    double gout87 = 0;
    double gout88 = 0;
    double gout89 = 0;
    double gout90 = 0;
    double gout91 = 0;
    double gout92 = 0;
    double gout93 = 0;
    double gout94 = 0;
    double gout95 = 0;
    double gout96 = 0;
    double gout97 = 0;
    double gout98 = 0;
    double gout99 = 0;
    double gout100 = 0;
    double gout101 = 0;
    double gout102 = 0;
    double gout103 = 0;
    double gout104 = 0;
    double gout105 = 0;
    double gout106 = 0;
    double gout107 = 0;
    double gout108 = 0;
    double gout109 = 0;
    double gout110 = 0;
    double gout111 = 0;
    double gout112 = 0;
    double gout113 = 0;
    double gout114 = 0;
    double gout115 = 0;
    double gout116 = 0;
    double gout117 = 0;
    double gout118 = 0;
    double gout119 = 0;
    double gout120 = 0;
    double gout121 = 0;
    double gout122 = 0;
    double gout123 = 0;
    double gout124 = 0;
    double gout125 = 0;
    double gout126 = 0;
    double gout127 = 0;
    double gout128 = 0;
    double gout129 = 0;
    double gout130 = 0;
    double gout131 = 0;
    double gout132 = 0;
    double gout133 = 0;
    double gout134 = 0;
    double gout135 = 0;
    double gout136 = 0;
    double gout137 = 0;
    double gout138 = 0;
    double gout139 = 0;
    double gout140 = 0;
    double gout141 = 0;
    double gout142 = 0;
    double gout143 = 0;
    double gout144 = 0;
    double gout145 = 0;
    double gout146 = 0;
    double gout147 = 0;
    double gout148 = 0;
    double gout149 = 0;
    double gout150 = 0;
    double gout151 = 0;
    double gout152 = 0;
    double gout153 = 0;
    double gout154 = 0;
    double gout155 = 0;
    double gout156 = 0;
    double gout157 = 0;
    double gout158 = 0;
    double gout159 = 0;
    double gout160 = 0;
    double gout161 = 0;
    double gout162 = 0;
    double gout163 = 0;
    double gout164 = 0;
    double gout165 = 0;
    double gout166 = 0;
    double gout167 = 0;
    double gout168 = 0;
    double gout169 = 0;
    double gout170 = 0;
    double gout171 = 0;
    double gout172 = 0;
    double gout173 = 0;
    double gout174 = 0;
    double gout175 = 0;
    double gout176 = 0;
    double gout177 = 0;
    double gout178 = 0;
    double gout179 = 0;
    double gout180 = 0;
    double gout181 = 0;
    double gout182 = 0;
    double gout183 = 0;
    double gout184 = 0;
    double gout185 = 0;
    double gout186 = 0;
    double gout187 = 0;
    double gout188 = 0;
    double gout189 = 0;
    double gout190 = 0;
    double gout191 = 0;
    double gout192 = 0;
    double gout193 = 0;
    double gout194 = 0;
    double gout195 = 0;
    double gout196 = 0;
    double gout197 = 0;
    double gout198 = 0;
    double gout199 = 0;
    double gout200 = 0;
    double gout201 = 0;
    double gout202 = 0;
    double gout203 = 0;
    double gout204 = 0;
    double gout205 = 0;
    double gout206 = 0;
    double gout207 = 0;
    double gout208 = 0;
    double gout209 = 0;
    double gout210 = 0;
    double gout211 = 0;
    double gout212 = 0;
    double gout213 = 0;
    double gout214 = 0;
    double gout215 = 0;
    double gout216 = 0;
    double gout217 = 0;
    double gout218 = 0;
    double gout219 = 0;
    double gout220 = 0;
    double gout221 = 0;
    double gout222 = 0;
    double gout223 = 0;
    double gout224 = 0;
    double gout225 = 0;
    double gout226 = 0;
    double gout227 = 0;
    double gout228 = 0;
    double gout229 = 0;
    double gout230 = 0;
    double gout231 = 0;
    double gout232 = 0;
    double gout233 = 0;
    double gout234 = 0;
    double gout235 = 0;
    double gout236 = 0;
    double gout237 = 0;
    double gout238 = 0;
    double gout239 = 0;
    double gout240 = 0;
    double gout241 = 0;
    double gout242 = 0;
    double gout243 = 0;
    double gout244 = 0;
    double gout245 = 0;
    double gout246 = 0;
    double gout247 = 0;
    double gout248 = 0;
    double gout249 = 0;
    double gout250 = 0;
    double gout251 = 0;
    double gout252 = 0;
    double gout253 = 0;
    double gout254 = 0;
    double gout255 = 0;
    double gout256 = 0;
    double gout257 = 0;
    double gout258 = 0;
    double gout259 = 0;
    double gout260 = 0;
    double gout261 = 0;
    double gout262 = 0;
    double gout263 = 0;
    double gout264 = 0;
    double gout265 = 0;
    double gout266 = 0;
    double gout267 = 0;
    double gout268 = 0;
    double gout269 = 0;
    double gout270 = 0;
    double gout271 = 0;
    double gout272 = 0;
    double gout273 = 0;
    double gout274 = 0;
    double gout275 = 0;
    double gout276 = 0;
    double gout277 = 0;
    double gout278 = 0;
    double gout279 = 0;
    double gout280 = 0;
    double gout281 = 0;
    double gout282 = 0;
    double gout283 = 0;
    double gout284 = 0;
    double gout285 = 0;
    double gout286 = 0;
    double gout287 = 0;
    double gout288 = 0;
    double gout289 = 0;
    double gout290 = 0;
    double gout291 = 0;
    double gout292 = 0;
    double gout293 = 0;
    double gout294 = 0;
    double gout295 = 0;
    double gout296 = 0;
    double gout297 = 0;
    double gout298 = 0;
    double gout299 = 0;
    double gout300 = 0;
    double gout301 = 0;
    double gout302 = 0;
    double gout303 = 0;
    double gout304 = 0;
    double gout305 = 0;
    double gout306 = 0;
    double gout307 = 0;
    double gout308 = 0;
    double gout309 = 0;
    double gout310 = 0;
    double gout311 = 0;
    double gout312 = 0;
    double gout313 = 0;
    double gout314 = 0;
    double gout315 = 0;
    double gout316 = 0;
    double gout317 = 0;
    double gout318 = 0;
    double gout319 = 0;
    double gout320 = 0;
    double gout321 = 0;
    double gout322 = 0;
    double gout323 = 0;

    double xi = bas_x[ish];
    double yi = bas_y[ish];
    double zi = bas_z[ish];
    double ABx = xi - bas_x[jsh];
    double ABy = yi - bas_y[jsh];
    double ABz = zi - bas_z[jsh];
    double xk = bas_x[ksh];
    double yk = bas_y[ksh];
    double zk = bas_z[ksh];
    double CDx = xk - bas_x[lsh];
    double CDy = yk - bas_y[lsh];
    double CDz = zk - bas_z[lsh];
    prim_ij0 = prim_ij;
    prim_ij1 = prim_ij + nprim_ij;
    prim_kl0 = prim_kl;
    prim_kl1 = prim_kl + nprim_kl;
    double rw[6];
    int irys;
    for (ij = prim_ij0; ij < prim_ij1; ++ij) {
        double alpha = i_exponent[ij];
        double beta = j_exponent[ij];
        double aij = a12[ij];
        double eij = e12[ij];
        double xij = x12[ij];
        double yij = y12[ij];
        double zij = z12[ij];
    for (kl = prim_kl0; kl < prim_kl1; ++kl) {
        double akl = a12[kl];
        double ekl = e12[kl];
        double xkl = x12[kl];
        double ykl = y12[kl];
        double zkl = z12[kl];
        double xijxkl = xij - xkl;
        double yijykl = yij - ykl;
        double zijzkl = zij - zkl;
        double aijkl = aij + akl;
        double a1 = aij * akl;
        double a0 = a1 / aijkl;
        double theta = omega > 0.0 ? omega * omega / (omega * omega + a0) : 1.0; 
        a0 *= theta;
        double x = a0 * (xijxkl * xijxkl + yijykl * yijykl + zijzkl * zijzkl);
        double fac = norm * eij * ekl * sqrt(a0 / (a1 * a1 * a1));
        //double fac = norm * eij * ekl / (sqrt(aijkl) * a1);

        GINTrys_root<3>(x, rw);
        GINTscale_u<3>(rw, theta);
      for (irys = 0; irys < 3; ++irys) {
            double weight0 = rw[irys+3] * fac;
            double root0 = rw[irys];
            double u2 = a0 * root0;
            double tmp4 = .5 / (u2 * aijkl + a1);
            double B00 = u2 * tmp4;
            double tmp1 = 2 * B00;
            double B10 = B00 + tmp4 * akl;
            double tmp2 = tmp1 * akl;
            double C00x = xij - xi - tmp2 * xijxkl;
            double C00y = yij - yi - tmp2 * yijykl;
            double C00z = zij - zi - tmp2 * zijzkl;
            double B01 = B00 + tmp4 * aij;
            double tmp3 = tmp1 * aij;
            double D00x = xkl - xk + tmp3 * xijxkl;
            double D00y = ykl - yk + tmp3 * yijykl;
            double D00z = zkl - zk + tmp3 * zijzkl;

            double g0 = B10+C00x*C00x;
            double g1 = C00x*D00x;
            double g2 = B00+g1;
            double g3 = 2*B00*C00x;
            double g4 = g0*D00x;
            double g5 = g3+g4;
            double g6 = B01+D00x*D00x;
            double g7 = 2*B00*D00x;
            double g8 = C00x*g6;
            double g9 = g7+g8;
            double g10 = 2*B00*B00;
            double g11 = 4*B00*C00x*D00x;
            double g12 = g0*g6;
            double g13 = g10+g11+g12;
            double g14 = ABx+C00x;
            double g15 = C00x*g14;
            double g16 = B10+g15;
            double g17 = g14*D00x;
            double g18 = B00+g17;
            double g19 = 2*C00x;
            double g20 = ABx+g19;
            double g21 = B00*g20;
            double g22 = g16*D00x;
            double g23 = g21+g22;
            double g25 = g7+(g14*g6);
            double g28 = g10+(2*B00*g20*D00x)+(g16*g6);
            double g29 = CDx+D00x;
            double g31 = B00+(C00x*g29);
            double g32 = g0*g29;
            double g33 = g3+g32;
            double g35 = B01+(D00x*g29);
            double g39 = CDx+(2*D00x);
            double g40 = B00*g39;
            double g41 = (B01*C00x)+(C00x*D00x*g29)+g40;
            double g44 = g10+(2*B00*C00x*g39)+(g0*g35);
            double g46 = 3*D00x;
            double g47 = CDx+g46;
            double g49 = (D00x*D00x*g29)+(B01*g47);
            double g50 = 3*B00*B01;
            double g54 = (2*CDx)+g46;
            double g56 = g50+(C00x*D00x*D00x*g29)+(B01*C00x*g47)+(B00*D00x*g54);
            double g57 = 2*B00*B00*g47;
            double g58 = g0*g49;
            double g59 = 3*B01;
            double g61 = g59+(D00x*g54);
            double g62 = 2*B00*C00x*g61;
            double g63 = g57+g58+g62;
            double g65 = B00+(g14*g29);
            double g67 = g3+g32+(ABx*g31);
            double g69 = g40+(g14*g35);
            double g72 = g10+(B00*g20*g39)+(g16*g35);
            double g75 = (g14*g49)+(B00*g61);
            double g77 = g57+g58+g62+(ABx*g56);
            double g78 = B10+C00y*C00y;
            double g80 = B00+(C00y*D00y);
            double g81 = 2*B00*C00y;
            double g83 = g81+(g78*D00y);
            double g84 = B01+D00y*D00y;
            double g85 = 2*B00*D00y;
            double g87 = g85+(C00y*g84);
            double g90 = g10+(4*B00*C00y*D00y)+(g78*g84);
            double g91 = ABy+C00y;
            double g93 = B10+(C00y*g91);
            double g95 = B00+(g91*D00y);
            double g97 = ABy+(2*C00y);
            double g100 = (B00*g97)+(g93*D00y);
            double g102 = g85+(g91*g84);
            double g105 = g10+(2*B00*g97*D00y)+(g93*g84);
            double g106 = CDy+D00y;
            double g108 = B00+(C00y*g106);
            double g109 = g78*g106;
            double g110 = g81+g109;
            double g112 = B01+(D00y*g106);
            double g116 = CDy+(2*D00y);
            double g117 = B00*g116;
            double g118 = (B01*C00y)+(C00y*D00y*g106)+g117;
            double g121 = g10+(2*B00*C00y*g116)+(g78*g112);
            double g123 = 3*D00y;
            double g124 = CDy+g123;
            double g126 = (D00y*D00y*g106)+(B01*g124);
            double g130 = (2*CDy)+g123;
            double g132 = g50+(C00y*D00y*D00y*g106)+(B01*C00y*g124)+(B00*D00y*g130);
            double g133 = 2*B00*B00*g124;
            double g134 = g78*g126;
            double g136 = g59+(D00y*g130);
            double g137 = 2*B00*C00y*g136;
            double g138 = g133+g134+g137;
            double g140 = B00+(g91*g106);
            double g142 = g81+g109+(ABy*g108);
            double g144 = g117+(g91*g112);
            double g147 = g10+(B00*g97*g116)+(g93*g112);
            double g150 = (g91*g126)+(B00*g136);
            double g152 = g133+g134+g137+(ABy*g132);
            double g153 = B10+C00z*C00z;
            double g155 = B00+(C00z*D00z);
            double g156 = 2*B00*C00z;
            double g158 = g156+(g153*D00z);
            double g159 = B01+D00z*D00z;
            double g160 = 2*B00*D00z;
            double g162 = g160+(C00z*g159);
            double g165 = g10+(4*B00*C00z*D00z)+(g153*g159);
            double g166 = ABz+C00z;
            double g168 = B10+(C00z*g166);
            double g170 = B00+(g166*D00z);
            double g172 = ABz+(2*C00z);
            double g175 = (B00*g172)+(g168*D00z);
            double g177 = g160+(g166*g159);
            double g180 = g10+(2*B00*g172*D00z)+(g168*g159);
            double g181 = CDz+D00z;
            double g183 = B00+(C00z*g181);
            double g184 = g153*g181;
            double g185 = g156+g184;
            double g187 = B01+(D00z*g181);
            double g191 = CDz+(2*D00z);
            double g192 = B00*g191;
            double g193 = (B01*C00z)+(C00z*D00z*g181)+g192;
            double g196 = g10+(2*B00*C00z*g191)+(g153*g187);
            double g198 = 3*D00z;
            double g199 = CDz+g198;
            double g201 = (D00z*D00z*g181)+(B01*g199);
            double g205 = (2*CDz)+g198;
            double g207 = g50+(C00z*D00z*D00z*g181)+(B01*C00z*g199)+(B00*D00z*g205);
            double g208 = 2*B00*B00*g199;
            double g209 = g153*g201;
            double g211 = g59+(D00z*g205);
            double g212 = 2*B00*C00z*g211;
            double g213 = g208+g209+g212;
            double g215 = B00+(g166*g181);
            double g217 = g156+g184+(ABz*g183);
            double g219 = g192+(g166*g187);
            double g222 = g10+(B00*g172*g191)+(g168*g187);
            double g225 = (g166*g201)+(B00*g211);
            double g227 = g208+g209+g212+(ABz*g207);

            gout0 += (-g49 + 2*alpha*g63) * weight0;
            gout1 += (-g6 + 2*alpha*g13) * (g106) * weight0;
            gout2 += (-g6 + 2*alpha*g13) * (g181) * weight0;
            gout3 += (-g35 + 2*alpha*g44) * (D00y) * weight0;
            gout4 += (-D00x + 2*alpha*g5) * (g112) * weight0;
            gout5 += (-D00x + 2*alpha*g5) * (D00y) * (g181) * weight0;
            gout6 += (-g35 + 2*alpha*g44) * (D00z) * weight0;
            gout7 += (-D00x + 2*alpha*g5) * (g106) * (D00z) * weight0;
            gout8 += (-D00x + 2*alpha*g5) * (g187) * weight0;
            gout9 += (-g29 + 2*alpha*g33) * (g84) * weight0;
            gout10 += (-1 + 2*alpha*g0) * (g126) * weight0;
            gout11 += (-1 + 2*alpha*g0) * (g84) * (g181) * weight0;
            gout12 += (-g29 + 2*alpha*g33) * (D00y) * (D00z) * weight0;
            gout13 += (-1 + 2*alpha*g0) * (g112) * (D00z) * weight0;
            gout14 += (-1 + 2*alpha*g0) * (D00y) * (g187) * weight0;
            gout15 += (-g29 + 2*alpha*g33) * (g159) * weight0;
            gout16 += (-1 + 2*alpha*g0) * (g106) * (g159) * weight0;
            gout17 += (-1 + 2*alpha*g0) * (g201) * weight0;
            gout18 += (2*alpha*g56) * (C00y) * weight0;
            gout19 += (2*alpha*g9) * (g108) * weight0;
            gout20 += (2*alpha*g9) * (C00y) * (g181) * weight0;
            gout21 += (2*alpha*g41) * (g80) * weight0;
            gout22 += (2*alpha*g2) * (g118) * weight0;
            gout23 += (2*alpha*g2) * (g80) * (g181) * weight0;
            gout24 += (2*alpha*g41) * (C00y) * (D00z) * weight0;
            gout25 += (2*alpha*g2) * (g108) * (D00z) * weight0;
            gout26 += (2*alpha*g2) * (C00y) * (g187) * weight0;
            gout27 += (2*alpha*g31) * (g87) * weight0;
            gout28 += (2*alpha*C00x) * (g132) * weight0;
            gout29 += (2*alpha*C00x) * (g87) * (g181) * weight0;
            gout30 += (2*alpha*g31) * (g80) * (D00z) * weight0;
            gout31 += (2*alpha*C00x) * (g118) * (D00z) * weight0;
            gout32 += (2*alpha*C00x) * (g80) * (g187) * weight0;
            gout33 += (2*alpha*g31) * (C00y) * (g159) * weight0;
            gout34 += (2*alpha*C00x) * (g108) * (g159) * weight0;
            gout35 += (2*alpha*C00x) * (C00y) * (g201) * weight0;
            gout36 += (2*alpha*g56) * (C00z) * weight0;
            gout37 += (2*alpha*g9) * (g106) * (C00z) * weight0;
            gout38 += (2*alpha*g9) * (g183) * weight0;
            gout39 += (2*alpha*g41) * (D00y) * (C00z) * weight0;
            gout40 += (2*alpha*g2) * (g112) * (C00z) * weight0;
            gout41 += (2*alpha*g2) * (D00y) * (g183) * weight0;
            gout42 += (2*alpha*g41) * (g155) * weight0;
            gout43 += (2*alpha*g2) * (g106) * (g155) * weight0;
            gout44 += (2*alpha*g2) * (g193) * weight0;
            gout45 += (2*alpha*g31) * (g84) * (C00z) * weight0;
            gout46 += (2*alpha*C00x) * (g126) * (C00z) * weight0;
            gout47 += (2*alpha*C00x) * (g84) * (g183) * weight0;
            gout48 += (2*alpha*g31) * (D00y) * (g155) * weight0;
            gout49 += (2*alpha*C00x) * (g112) * (g155) * weight0;
            gout50 += (2*alpha*C00x) * (D00y) * (g193) * weight0;
            gout51 += (2*alpha*g31) * (g162) * weight0;
            gout52 += (2*alpha*C00x) * (g106) * (g162) * weight0;
            gout53 += (2*alpha*C00x) * (g207) * weight0;
            gout54 += (g56) * (2*alpha*C00y) * weight0;
            gout55 += (g9) * (2*alpha*g108) * weight0;
            gout56 += (g9) * (2*alpha*C00y) * (g181) * weight0;
            gout57 += (g41) * (2*alpha*g80) * weight0;
            gout58 += (g2) * (2*alpha*g118) * weight0;
            gout59 += (g2) * (2*alpha*g80) * (g181) * weight0;
            gout60 += (g41) * (2*alpha*C00y) * (D00z) * weight0;
            gout61 += (g2) * (2*alpha*g108) * (D00z) * weight0;
            gout62 += (g2) * (2*alpha*C00y) * (g187) * weight0;
            gout63 += (g31) * (2*alpha*g87) * weight0;
            gout64 += (C00x) * (2*alpha*g132) * weight0;
            gout65 += (C00x) * (2*alpha*g87) * (g181) * weight0;
            gout66 += (g31) * (2*alpha*g80) * (D00z) * weight0;
            gout67 += (C00x) * (2*alpha*g118) * (D00z) * weight0;
            gout68 += (C00x) * (2*alpha*g80) * (g187) * weight0;
            gout69 += (g31) * (2*alpha*C00y) * (g159) * weight0;
            gout70 += (C00x) * (2*alpha*g108) * (g159) * weight0;
            gout71 += (C00x) * (2*alpha*C00y) * (g201) * weight0;
            gout72 += (g49) * (-1 + 2*alpha*g78) * weight0;
            gout73 += (g6) * (-g106 + 2*alpha*g110) * weight0;
            gout74 += (g6) * (-1 + 2*alpha*g78) * (g181) * weight0;
            gout75 += (g35) * (-D00y + 2*alpha*g83) * weight0;
            gout76 += (D00x) * (-g112 + 2*alpha*g121) * weight0;
            gout77 += (D00x) * (-D00y + 2*alpha*g83) * (g181) * weight0;
            gout78 += (g35) * (-1 + 2*alpha*g78) * (D00z) * weight0;
            gout79 += (D00x) * (-g106 + 2*alpha*g110) * (D00z) * weight0;
            gout80 += (D00x) * (-1 + 2*alpha*g78) * (g187) * weight0;
            gout81 += (g29) * (-g84 + 2*alpha*g90) * weight0;
            gout82 += (-g126 + 2*alpha*g138) * weight0;
            gout83 += (-g84 + 2*alpha*g90) * (g181) * weight0;
            gout84 += (g29) * (-D00y + 2*alpha*g83) * (D00z) * weight0;
            gout85 += (-g112 + 2*alpha*g121) * (D00z) * weight0;
            gout86 += (-D00y + 2*alpha*g83) * (g187) * weight0;
            gout87 += (g29) * (-1 + 2*alpha*g78) * (g159) * weight0;
            gout88 += (-g106 + 2*alpha*g110) * (g159) * weight0;
            gout89 += (-1 + 2*alpha*g78) * (g201) * weight0;
            gout90 += (g49) * (2*alpha*C00y) * (C00z) * weight0;
            gout91 += (g6) * (2*alpha*g108) * (C00z) * weight0;
            gout92 += (g6) * (2*alpha*C00y) * (g183) * weight0;
            gout93 += (g35) * (2*alpha*g80) * (C00z) * weight0;
            gout94 += (D00x) * (2*alpha*g118) * (C00z) * weight0;
            gout95 += (D00x) * (2*alpha*g80) * (g183) * weight0;
            gout96 += (g35) * (2*alpha*C00y) * (g155) * weight0;
            gout97 += (D00x) * (2*alpha*g108) * (g155) * weight0;
            gout98 += (D00x) * (2*alpha*C00y) * (g193) * weight0;
            gout99 += (g29) * (2*alpha*g87) * (C00z) * weight0;
            gout100 += (2*alpha*g132) * (C00z) * weight0;
            gout101 += (2*alpha*g87) * (g183) * weight0;
            gout102 += (g29) * (2*alpha*g80) * (g155) * weight0;
            gout103 += (2*alpha*g118) * (g155) * weight0;
            gout104 += (2*alpha*g80) * (g193) * weight0;
            gout105 += (g29) * (2*alpha*C00y) * (g162) * weight0;
            gout106 += (2*alpha*g108) * (g162) * weight0;
            gout107 += (2*alpha*C00y) * (g207) * weight0;
            gout108 += (g56) * (2*alpha*C00z) * weight0;
            gout109 += (g9) * (g106) * (2*alpha*C00z) * weight0;
            gout110 += (g9) * (2*alpha*g183) * weight0;
            gout111 += (g41) * (D00y) * (2*alpha*C00z) * weight0;
            gout112 += (g2) * (g112) * (2*alpha*C00z) * weight0;
            gout113 += (g2) * (D00y) * (2*alpha*g183) * weight0;
            gout114 += (g41) * (2*alpha*g155) * weight0;
            gout115 += (g2) * (g106) * (2*alpha*g155) * weight0;
            gout116 += (g2) * (2*alpha*g193) * weight0;
            gout117 += (g31) * (g84) * (2*alpha*C00z) * weight0;
            gout118 += (C00x) * (g126) * (2*alpha*C00z) * weight0;
            gout119 += (C00x) * (g84) * (2*alpha*g183) * weight0;
            gout120 += (g31) * (D00y) * (2*alpha*g155) * weight0;
            gout121 += (C00x) * (g112) * (2*alpha*g155) * weight0;
            gout122 += (C00x) * (D00y) * (2*alpha*g193) * weight0;
            gout123 += (g31) * (2*alpha*g162) * weight0;
            gout124 += (C00x) * (g106) * (2*alpha*g162) * weight0;
            gout125 += (C00x) * (2*alpha*g207) * weight0;
            gout126 += (g49) * (C00y) * (2*alpha*C00z) * weight0;
            gout127 += (g6) * (g108) * (2*alpha*C00z) * weight0;
            gout128 += (g6) * (C00y) * (2*alpha*g183) * weight0;
            gout129 += (g35) * (g80) * (2*alpha*C00z) * weight0;
            gout130 += (D00x) * (g118) * (2*alpha*C00z) * weight0;
            gout131 += (D00x) * (g80) * (2*alpha*g183) * weight0;
            gout132 += (g35) * (C00y) * (2*alpha*g155) * weight0;
            gout133 += (D00x) * (g108) * (2*alpha*g155) * weight0;
            gout134 += (D00x) * (C00y) * (2*alpha*g193) * weight0;
            gout135 += (g29) * (g87) * (2*alpha*C00z) * weight0;
            gout136 += (g132) * (2*alpha*C00z) * weight0;
            gout137 += (g87) * (2*alpha*g183) * weight0;
            gout138 += (g29) * (g80) * (2*alpha*g155) * weight0;
            gout139 += (g118) * (2*alpha*g155) * weight0;
            gout140 += (g80) * (2*alpha*g193) * weight0;
            gout141 += (g29) * (C00y) * (2*alpha*g162) * weight0;
            gout142 += (g108) * (2*alpha*g162) * weight0;
            gout143 += (C00y) * (2*alpha*g207) * weight0;
            gout144 += (g49) * (-1 + 2*alpha*g153) * weight0;
            gout145 += (g6) * (g106) * (-1 + 2*alpha*g153) * weight0;
            gout146 += (g6) * (-g181 + 2*alpha*g185) * weight0;
            gout147 += (g35) * (D00y) * (-1 + 2*alpha*g153) * weight0;
            gout148 += (D00x) * (g112) * (-1 + 2*alpha*g153) * weight0;
            gout149 += (D00x) * (D00y) * (-g181 + 2*alpha*g185) * weight0;
            gout150 += (g35) * (-D00z + 2*alpha*g158) * weight0;
            gout151 += (D00x) * (g106) * (-D00z + 2*alpha*g158) * weight0;
            gout152 += (D00x) * (-g187 + 2*alpha*g196) * weight0;
            gout153 += (g29) * (g84) * (-1 + 2*alpha*g153) * weight0;
            gout154 += (g126) * (-1 + 2*alpha*g153) * weight0;
            gout155 += (g84) * (-g181 + 2*alpha*g185) * weight0;
            gout156 += (g29) * (D00y) * (-D00z + 2*alpha*g158) * weight0;
            gout157 += (g112) * (-D00z + 2*alpha*g158) * weight0;
            gout158 += (D00y) * (-g187 + 2*alpha*g196) * weight0;
            gout159 += (g29) * (-g159 + 2*alpha*g165) * weight0;
            gout160 += (g106) * (-g159 + 2*alpha*g165) * weight0;
            gout161 += (-g201 + 2*alpha*g213) * weight0;
            gout162 += (2*beta*g77) * weight0;
            gout163 += (2*beta*g28) * (g106) * weight0;
            gout164 += (2*beta*g28) * (g181) * weight0;
            gout165 += (2*beta*g72) * (D00y) * weight0;
            gout166 += (2*beta*g23) * (g112) * weight0;
            gout167 += (2*beta*g23) * (D00y) * (g181) * weight0;
            gout168 += (2*beta*g72) * (D00z) * weight0;
            gout169 += (2*beta*g23) * (g106) * (D00z) * weight0;
            gout170 += (2*beta*g23) * (g187) * weight0;
            gout171 += (2*beta*g67) * (g84) * weight0;
            gout172 += (2*beta*g16) * (g126) * weight0;
            gout173 += (2*beta*g16) * (g84) * (g181) * weight0;
            gout174 += (2*beta*g67) * (D00y) * (D00z) * weight0;
            gout175 += (2*beta*g16) * (g112) * (D00z) * weight0;
            gout176 += (2*beta*g16) * (D00y) * (g187) * weight0;
            gout177 += (2*beta*g67) * (g159) * weight0;
            gout178 += (2*beta*g16) * (g106) * (g159) * weight0;
            gout179 += (2*beta*g16) * (g201) * weight0;
            gout180 += (2*beta*g75) * (C00y) * weight0;
            gout181 += (2*beta*g25) * (g108) * weight0;
            gout182 += (2*beta*g25) * (C00y) * (g181) * weight0;
            gout183 += (2*beta*g69) * (g80) * weight0;
            gout184 += (2*beta*g18) * (g118) * weight0;
            gout185 += (2*beta*g18) * (g80) * (g181) * weight0;
            gout186 += (2*beta*g69) * (C00y) * (D00z) * weight0;
            gout187 += (2*beta*g18) * (g108) * (D00z) * weight0;
            gout188 += (2*beta*g18) * (C00y) * (g187) * weight0;
            gout189 += (2*beta*g65) * (g87) * weight0;
            gout190 += (2*beta*g14) * (g132) * weight0;
            gout191 += (2*beta*g14) * (g87) * (g181) * weight0;
            gout192 += (2*beta*g65) * (g80) * (D00z) * weight0;
            gout193 += (2*beta*g14) * (g118) * (D00z) * weight0;
            gout194 += (2*beta*g14) * (g80) * (g187) * weight0;
            gout195 += (2*beta*g65) * (C00y) * (g159) * weight0;
            gout196 += (2*beta*g14) * (g108) * (g159) * weight0;
            gout197 += (2*beta*g14) * (C00y) * (g201) * weight0;
            gout198 += (2*beta*g75) * (C00z) * weight0;
            gout199 += (2*beta*g25) * (g106) * (C00z) * weight0;
            gout200 += (2*beta*g25) * (g183) * weight0;
            gout201 += (2*beta*g69) * (D00y) * (C00z) * weight0;
            gout202 += (2*beta*g18) * (g112) * (C00z) * weight0;
            gout203 += (2*beta*g18) * (D00y) * (g183) * weight0;
            gout204 += (2*beta*g69) * (g155) * weight0;
            gout205 += (2*beta*g18) * (g106) * (g155) * weight0;
            gout206 += (2*beta*g18) * (g193) * weight0;
            gout207 += (2*beta*g65) * (g84) * (C00z) * weight0;
            gout208 += (2*beta*g14) * (g126) * (C00z) * weight0;
            gout209 += (2*beta*g14) * (g84) * (g183) * weight0;
            gout210 += (2*beta*g65) * (D00y) * (g155) * weight0;
            gout211 += (2*beta*g14) * (g112) * (g155) * weight0;
            gout212 += (2*beta*g14) * (D00y) * (g193) * weight0;
            gout213 += (2*beta*g65) * (g162) * weight0;
            gout214 += (2*beta*g14) * (g106) * (g162) * weight0;
            gout215 += (2*beta*g14) * (g207) * weight0;
            gout216 += (g56) * (2*beta*g91) * weight0;
            gout217 += (g9) * (2*beta*g140) * weight0;
            gout218 += (g9) * (2*beta*g91) * (g181) * weight0;
            gout219 += (g41) * (2*beta*g95) * weight0;
            gout220 += (g2) * (2*beta*g144) * weight0;
            gout221 += (g2) * (2*beta*g95) * (g181) * weight0;
            gout222 += (g41) * (2*beta*g91) * (D00z) * weight0;
            gout223 += (g2) * (2*beta*g140) * (D00z) * weight0;
            gout224 += (g2) * (2*beta*g91) * (g187) * weight0;
            gout225 += (g31) * (2*beta*g102) * weight0;
            gout226 += (C00x) * (2*beta*g150) * weight0;
            gout227 += (C00x) * (2*beta*g102) * (g181) * weight0;
            gout228 += (g31) * (2*beta*g95) * (D00z) * weight0;
            gout229 += (C00x) * (2*beta*g144) * (D00z) * weight0;
            gout230 += (C00x) * (2*beta*g95) * (g187) * weight0;
            gout231 += (g31) * (2*beta*g91) * (g159) * weight0;
            gout232 += (C00x) * (2*beta*g140) * (g159) * weight0;
            gout233 += (C00x) * (2*beta*g91) * (g201) * weight0;
            gout234 += (g49) * (2*beta*g93) * weight0;
            gout235 += (g6) * (2*beta*g142) * weight0;
            gout236 += (g6) * (2*beta*g93) * (g181) * weight0;
            gout237 += (g35) * (2*beta*g100) * weight0;
            gout238 += (D00x) * (2*beta*g147) * weight0;
            gout239 += (D00x) * (2*beta*g100) * (g181) * weight0;
            gout240 += (g35) * (2*beta*g93) * (D00z) * weight0;
            gout241 += (D00x) * (2*beta*g142) * (D00z) * weight0;
            gout242 += (D00x) * (2*beta*g93) * (g187) * weight0;
            gout243 += (g29) * (2*beta*g105) * weight0;
            gout244 += (2*beta*g152) * weight0;
            gout245 += (2*beta*g105) * (g181) * weight0;
            gout246 += (g29) * (2*beta*g100) * (D00z) * weight0;
            gout247 += (2*beta*g147) * (D00z) * weight0;
            gout248 += (2*beta*g100) * (g187) * weight0;
            gout249 += (g29) * (2*beta*g93) * (g159) * weight0;
            gout250 += (2*beta*g142) * (g159) * weight0;
            gout251 += (2*beta*g93) * (g201) * weight0;
            gout252 += (g49) * (2*beta*g91) * (C00z) * weight0;
            gout253 += (g6) * (2*beta*g140) * (C00z) * weight0;
            gout254 += (g6) * (2*beta*g91) * (g183) * weight0;
            gout255 += (g35) * (2*beta*g95) * (C00z) * weight0;
            gout256 += (D00x) * (2*beta*g144) * (C00z) * weight0;
            gout257 += (D00x) * (2*beta*g95) * (g183) * weight0;
            gout258 += (g35) * (2*beta*g91) * (g155) * weight0;
            gout259 += (D00x) * (2*beta*g140) * (g155) * weight0;
            gout260 += (D00x) * (2*beta*g91) * (g193) * weight0;
            gout261 += (g29) * (2*beta*g102) * (C00z) * weight0;
            gout262 += (2*beta*g150) * (C00z) * weight0;
            gout263 += (2*beta*g102) * (g183) * weight0;
            gout264 += (g29) * (2*beta*g95) * (g155) * weight0;
            gout265 += (2*beta*g144) * (g155) * weight0;
            gout266 += (2*beta*g95) * (g193) * weight0;
            gout267 += (g29) * (2*beta*g91) * (g162) * weight0;
            gout268 += (2*beta*g140) * (g162) * weight0;
            gout269 += (2*beta*g91) * (g207) * weight0;
            gout270 += (g56) * (2*beta*g166) * weight0;
            gout271 += (g9) * (g106) * (2*beta*g166) * weight0;
            gout272 += (g9) * (2*beta*g215) * weight0;
            gout273 += (g41) * (D00y) * (2*beta*g166) * weight0;
            gout274 += (g2) * (g112) * (2*beta*g166) * weight0;
            gout275 += (g2) * (D00y) * (2*beta*g215) * weight0;
            gout276 += (g41) * (2*beta*g170) * weight0;
            gout277 += (g2) * (g106) * (2*beta*g170) * weight0;
            gout278 += (g2) * (2*beta*g219) * weight0;
            gout279 += (g31) * (g84) * (2*beta*g166) * weight0;
            gout280 += (C00x) * (g126) * (2*beta*g166) * weight0;
            gout281 += (C00x) * (g84) * (2*beta*g215) * weight0;
            gout282 += (g31) * (D00y) * (2*beta*g170) * weight0;
            gout283 += (C00x) * (g112) * (2*beta*g170) * weight0;
            gout284 += (C00x) * (D00y) * (2*beta*g219) * weight0;
            gout285 += (g31) * (2*beta*g177) * weight0;
            gout286 += (C00x) * (g106) * (2*beta*g177) * weight0;
            gout287 += (C00x) * (2*beta*g225) * weight0;
            gout288 += (g49) * (C00y) * (2*beta*g166) * weight0;
            gout289 += (g6) * (g108) * (2*beta*g166) * weight0;
            gout290 += (g6) * (C00y) * (2*beta*g215) * weight0;
            gout291 += (g35) * (g80) * (2*beta*g166) * weight0;
            gout292 += (D00x) * (g118) * (2*beta*g166) * weight0;
            gout293 += (D00x) * (g80) * (2*beta*g215) * weight0;
            gout294 += (g35) * (C00y) * (2*beta*g170) * weight0;
            gout295 += (D00x) * (g108) * (2*beta*g170) * weight0;
            gout296 += (D00x) * (C00y) * (2*beta*g219) * weight0;
            gout297 += (g29) * (g87) * (2*beta*g166) * weight0;
            gout298 += (g132) * (2*beta*g166) * weight0;
            gout299 += (g87) * (2*beta*g215) * weight0;
            gout300 += (g29) * (g80) * (2*beta*g170) * weight0;
            gout301 += (g118) * (2*beta*g170) * weight0;
            gout302 += (g80) * (2*beta*g219) * weight0;
            gout303 += (g29) * (C00y) * (2*beta*g177) * weight0;
            gout304 += (g108) * (2*beta*g177) * weight0;
            gout305 += (C00y) * (2*beta*g225) * weight0;
            gout306 += (g49) * (2*beta*g168) * weight0;
            gout307 += (g6) * (g106) * (2*beta*g168) * weight0;
            gout308 += (g6) * (2*beta*g217) * weight0;
            gout309 += (g35) * (D00y) * (2*beta*g168) * weight0;
            gout310 += (D00x) * (g112) * (2*beta*g168) * weight0;
            gout311 += (D00x) * (D00y) * (2*beta*g217) * weight0;
            gout312 += (g35) * (2*beta*g175) * weight0;
            gout313 += (D00x) * (g106) * (2*beta*g175) * weight0;
            gout314 += (D00x) * (2*beta*g222) * weight0;
            gout315 += (g29) * (g84) * (2*beta*g168) * weight0;
            gout316 += (g126) * (2*beta*g168) * weight0;
            gout317 += (g84) * (2*beta*g217) * weight0;
            gout318 += (g29) * (D00y) * (2*beta*g175) * weight0;
            gout319 += (g112) * (2*beta*g175) * weight0;
            gout320 += (D00y) * (2*beta*g222) * weight0;
            gout321 += (g29) * (2*beta*g180) * weight0;
            gout322 += (g106) * (2*beta*g180) * weight0;
            gout323 += (2*beta*g227) * weight0;
        }
    } }

    int *ao_loc = c_bpcache.ao_loc;
    int i0 = ao_loc[ish];
    int j0 = ao_loc[jsh];
    int k0 = ao_loc[ksh];
    int l0 = ao_loc[lsh];
    int n_dm = jk.n_dm;
    int nao = jk.nao;
    size_t nao2 = nao * nao;
    double* __restrict__ dm = jk.dm;
    double *vj = jk.vj;
    double *vk = jk.vk;
    double d_0, d_1, d_2, d_3, d_4, d_5, d_6, d_7, d_8, d_9, d_10, d_11, d_12, d_13, d_14, d_15, d_16, d_17;

    for (int i_dm = 0; i_dm < n_dm; ++i_dm) {
        if (vj != NULL) {
            d_0 = dm[(k0+0)+nao*(l0+0)];
            d_1 = dm[(k0+0)+nao*(l0+1)];
            d_2 = dm[(k0+0)+nao*(l0+2)];
            d_3 = dm[(k0+1)+nao*(l0+0)];
            d_4 = dm[(k0+1)+nao*(l0+1)];
            d_5 = dm[(k0+1)+nao*(l0+2)];
            d_6 = dm[(k0+2)+nao*(l0+0)];
            d_7 = dm[(k0+2)+nao*(l0+1)];
            d_8 = dm[(k0+2)+nao*(l0+2)];
            d_9 = dm[(k0+3)+nao*(l0+0)];
            d_10 = dm[(k0+3)+nao*(l0+1)];
            d_11 = dm[(k0+3)+nao*(l0+2)];
            d_12 = dm[(k0+4)+nao*(l0+0)];
            d_13 = dm[(k0+4)+nao*(l0+1)];
            d_14 = dm[(k0+4)+nao*(l0+2)];
            d_15 = dm[(k0+5)+nao*(l0+0)];
            d_16 = dm[(k0+5)+nao*(l0+1)];
            d_17 = dm[(k0+5)+nao*(l0+2)];
            atomicAdd(vj+(i0+0)+nao*(j0+0), gout0*d_0+gout1*d_1+gout2*d_2+gout3*d_3+gout4*d_4+gout5*d_5+gout6*d_6+gout7*d_7+gout8*d_8+gout9*d_9+gout10*d_10+gout11*d_11+gout12*d_12+gout13*d_13+gout14*d_14+gout15*d_15+gout16*d_16+gout17*d_17);
            atomicAdd(vj+(i0+1)+nao*(j0+0), gout18*d_0+gout19*d_1+gout20*d_2+gout21*d_3+gout22*d_4+gout23*d_5+gout24*d_6+gout25*d_7+gout26*d_8+gout27*d_9+gout28*d_10+gout29*d_11+gout30*d_12+gout31*d_13+gout32*d_14+gout33*d_15+gout34*d_16+gout35*d_17);
            atomicAdd(vj+(i0+2)+nao*(j0+0), gout36*d_0+gout37*d_1+gout38*d_2+gout39*d_3+gout40*d_4+gout41*d_5+gout42*d_6+gout43*d_7+gout44*d_8+gout45*d_9+gout46*d_10+gout47*d_11+gout48*d_12+gout49*d_13+gout50*d_14+gout51*d_15+gout52*d_16+gout53*d_17);
            atomicAdd(vj+(i0+0)+nao*(j0+0)+nao2, gout54*d_0+gout55*d_1+gout56*d_2+gout57*d_3+gout58*d_4+gout59*d_5+gout60*d_6+gout61*d_7+gout62*d_8+gout63*d_9+gout64*d_10+gout65*d_11+gout66*d_12+gout67*d_13+gout68*d_14+gout69*d_15+gout70*d_16+gout71*d_17);
            atomicAdd(vj+(i0+1)+nao*(j0+0)+nao2, gout72*d_0+gout73*d_1+gout74*d_2+gout75*d_3+gout76*d_4+gout77*d_5+gout78*d_6+gout79*d_7+gout80*d_8+gout81*d_9+gout82*d_10+gout83*d_11+gout84*d_12+gout85*d_13+gout86*d_14+gout87*d_15+gout88*d_16+gout89*d_17);
            atomicAdd(vj+(i0+2)+nao*(j0+0)+nao2, gout90*d_0+gout91*d_1+gout92*d_2+gout93*d_3+gout94*d_4+gout95*d_5+gout96*d_6+gout97*d_7+gout98*d_8+gout99*d_9+gout100*d_10+gout101*d_11+gout102*d_12+gout103*d_13+gout104*d_14+gout105*d_15+gout106*d_16+gout107*d_17);
            atomicAdd(vj+(i0+0)+nao*(j0+0)+2*nao2, gout108*d_0+gout109*d_1+gout110*d_2+gout111*d_3+gout112*d_4+gout113*d_5+gout114*d_6+gout115*d_7+gout116*d_8+gout117*d_9+gout118*d_10+gout119*d_11+gout120*d_12+gout121*d_13+gout122*d_14+gout123*d_15+gout124*d_16+gout125*d_17);
            atomicAdd(vj+(i0+1)+nao*(j0+0)+2*nao2, gout126*d_0+gout127*d_1+gout128*d_2+gout129*d_3+gout130*d_4+gout131*d_5+gout132*d_6+gout133*d_7+gout134*d_8+gout135*d_9+gout136*d_10+gout137*d_11+gout138*d_12+gout139*d_13+gout140*d_14+gout141*d_15+gout142*d_16+gout143*d_17);
            atomicAdd(vj+(i0+2)+nao*(j0+0)+2*nao2, gout144*d_0+gout145*d_1+gout146*d_2+gout147*d_3+gout148*d_4+gout149*d_5+gout150*d_6+gout151*d_7+gout152*d_8+gout153*d_9+gout154*d_10+gout155*d_11+gout156*d_12+gout157*d_13+gout158*d_14+gout159*d_15+gout160*d_16+gout161*d_17);
            atomicAdd(vj+nao*(i0+0)+(j0+0), gout162*d_0+gout163*d_1+gout164*d_2+gout165*d_3+gout166*d_4+gout167*d_5+gout168*d_6+gout169*d_7+gout170*d_8+gout171*d_9+gout172*d_10+gout173*d_11+gout174*d_12+gout175*d_13+gout176*d_14+gout177*d_15+gout178*d_16+gout179*d_17);
            atomicAdd(vj+nao*(i0+1)+(j0+0), gout180*d_0+gout181*d_1+gout182*d_2+gout183*d_3+gout184*d_4+gout185*d_5+gout186*d_6+gout187*d_7+gout188*d_8+gout189*d_9+gout190*d_10+gout191*d_11+gout192*d_12+gout193*d_13+gout194*d_14+gout195*d_15+gout196*d_16+gout197*d_17);
            atomicAdd(vj+nao*(i0+2)+(j0+0), gout198*d_0+gout199*d_1+gout200*d_2+gout201*d_3+gout202*d_4+gout203*d_5+gout204*d_6+gout205*d_7+gout206*d_8+gout207*d_9+gout208*d_10+gout209*d_11+gout210*d_12+gout211*d_13+gout212*d_14+gout213*d_15+gout214*d_16+gout215*d_17);
            atomicAdd(vj+nao*(i0+0)+(j0+0)+nao2, gout216*d_0+gout217*d_1+gout218*d_2+gout219*d_3+gout220*d_4+gout221*d_5+gout222*d_6+gout223*d_7+gout224*d_8+gout225*d_9+gout226*d_10+gout227*d_11+gout228*d_12+gout229*d_13+gout230*d_14+gout231*d_15+gout232*d_16+gout233*d_17);
            atomicAdd(vj+nao*(i0+1)+(j0+0)+nao2, gout234*d_0+gout235*d_1+gout236*d_2+gout237*d_3+gout238*d_4+gout239*d_5+gout240*d_6+gout241*d_7+gout242*d_8+gout243*d_9+gout244*d_10+gout245*d_11+gout246*d_12+gout247*d_13+gout248*d_14+gout249*d_15+gout250*d_16+gout251*d_17);
            atomicAdd(vj+nao*(i0+2)+(j0+0)+nao2, gout252*d_0+gout253*d_1+gout254*d_2+gout255*d_3+gout256*d_4+gout257*d_5+gout258*d_6+gout259*d_7+gout260*d_8+gout261*d_9+gout262*d_10+gout263*d_11+gout264*d_12+gout265*d_13+gout266*d_14+gout267*d_15+gout268*d_16+gout269*d_17);
            atomicAdd(vj+nao*(i0+0)+(j0+0)+2*nao2, gout270*d_0+gout271*d_1+gout272*d_2+gout273*d_3+gout274*d_4+gout275*d_5+gout276*d_6+gout277*d_7+gout278*d_8+gout279*d_9+gout280*d_10+gout281*d_11+gout282*d_12+gout283*d_13+gout284*d_14+gout285*d_15+gout286*d_16+gout287*d_17);
            atomicAdd(vj+nao*(i0+1)+(j0+0)+2*nao2, gout288*d_0+gout289*d_1+gout290*d_2+gout291*d_3+gout292*d_4+gout293*d_5+gout294*d_6+gout295*d_7+gout296*d_8+gout297*d_9+gout298*d_10+gout299*d_11+gout300*d_12+gout301*d_13+gout302*d_14+gout303*d_15+gout304*d_16+gout305*d_17);
            atomicAdd(vj+nao*(i0+2)+(j0+0)+2*nao2, gout306*d_0+gout307*d_1+gout308*d_2+gout309*d_3+gout310*d_4+gout311*d_5+gout312*d_6+gout313*d_7+gout314*d_8+gout315*d_9+gout316*d_10+gout317*d_11+gout318*d_12+gout319*d_13+gout320*d_14+gout321*d_15+gout322*d_16+gout323*d_17);
            vj += 3*nao2;
        }
        if (vk != NULL) {
            // ijkl, jk -> il
            d_0 = dm[(j0+0)+nao*(k0+0)];
            d_1 = dm[(j0+0)+nao*(k0+1)];
            d_2 = dm[(j0+0)+nao*(k0+2)];
            d_3 = dm[(j0+0)+nao*(k0+3)];
            d_4 = dm[(j0+0)+nao*(k0+4)];
            d_5 = dm[(j0+0)+nao*(k0+5)];
            atomicAdd(vk+(i0+0)+nao*(l0+0), gout0*d_0+gout3*d_1+gout6*d_2+gout9*d_3+gout12*d_4+gout15*d_5);
            atomicAdd(vk+(i0+0)+nao*(l0+1), gout1*d_0+gout4*d_1+gout7*d_2+gout10*d_3+gout13*d_4+gout16*d_5);
            atomicAdd(vk+(i0+0)+nao*(l0+2), gout2*d_0+gout5*d_1+gout8*d_2+gout11*d_3+gout14*d_4+gout17*d_5);
            atomicAdd(vk+(i0+1)+nao*(l0+0), gout18*d_0+gout21*d_1+gout24*d_2+gout27*d_3+gout30*d_4+gout33*d_5);
            atomicAdd(vk+(i0+1)+nao*(l0+1), gout19*d_0+gout22*d_1+gout25*d_2+gout28*d_3+gout31*d_4+gout34*d_5);
            atomicAdd(vk+(i0+1)+nao*(l0+2), gout20*d_0+gout23*d_1+gout26*d_2+gout29*d_3+gout32*d_4+gout35*d_5);
            atomicAdd(vk+(i0+2)+nao*(l0+0), gout36*d_0+gout39*d_1+gout42*d_2+gout45*d_3+gout48*d_4+gout51*d_5);
            atomicAdd(vk+(i0+2)+nao*(l0+1), gout37*d_0+gout40*d_1+gout43*d_2+gout46*d_3+gout49*d_4+gout52*d_5);
            atomicAdd(vk+(i0+2)+nao*(l0+2), gout38*d_0+gout41*d_1+gout44*d_2+gout47*d_3+gout50*d_4+gout53*d_5);
            atomicAdd(vk+(i0+0)+nao*(l0+0)+nao2, gout54*d_0+gout57*d_1+gout60*d_2+gout63*d_3+gout66*d_4+gout69*d_5);
            atomicAdd(vk+(i0+0)+nao*(l0+1)+nao2, gout55*d_0+gout58*d_1+gout61*d_2+gout64*d_3+gout67*d_4+gout70*d_5);
            atomicAdd(vk+(i0+0)+nao*(l0+2)+nao2, gout56*d_0+gout59*d_1+gout62*d_2+gout65*d_3+gout68*d_4+gout71*d_5);
            atomicAdd(vk+(i0+1)+nao*(l0+0)+nao2, gout72*d_0+gout75*d_1+gout78*d_2+gout81*d_3+gout84*d_4+gout87*d_5);
            atomicAdd(vk+(i0+1)+nao*(l0+1)+nao2, gout73*d_0+gout76*d_1+gout79*d_2+gout82*d_3+gout85*d_4+gout88*d_5);
            atomicAdd(vk+(i0+1)+nao*(l0+2)+nao2, gout74*d_0+gout77*d_1+gout80*d_2+gout83*d_3+gout86*d_4+gout89*d_5);
            atomicAdd(vk+(i0+2)+nao*(l0+0)+nao2, gout90*d_0+gout93*d_1+gout96*d_2+gout99*d_3+gout102*d_4+gout105*d_5);
            atomicAdd(vk+(i0+2)+nao*(l0+1)+nao2, gout91*d_0+gout94*d_1+gout97*d_2+gout100*d_3+gout103*d_4+gout106*d_5);
            atomicAdd(vk+(i0+2)+nao*(l0+2)+nao2, gout92*d_0+gout95*d_1+gout98*d_2+gout101*d_3+gout104*d_4+gout107*d_5);
            atomicAdd(vk+(i0+0)+nao*(l0+0)+2*nao2, gout108*d_0+gout111*d_1+gout114*d_2+gout117*d_3+gout120*d_4+gout123*d_5);
            atomicAdd(vk+(i0+0)+nao*(l0+1)+2*nao2, gout109*d_0+gout112*d_1+gout115*d_2+gout118*d_3+gout121*d_4+gout124*d_5);
            atomicAdd(vk+(i0+0)+nao*(l0+2)+2*nao2, gout110*d_0+gout113*d_1+gout116*d_2+gout119*d_3+gout122*d_4+gout125*d_5);
            atomicAdd(vk+(i0+1)+nao*(l0+0)+2*nao2, gout126*d_0+gout129*d_1+gout132*d_2+gout135*d_3+gout138*d_4+gout141*d_5);
            atomicAdd(vk+(i0+1)+nao*(l0+1)+2*nao2, gout127*d_0+gout130*d_1+gout133*d_2+gout136*d_3+gout139*d_4+gout142*d_5);
            atomicAdd(vk+(i0+1)+nao*(l0+2)+2*nao2, gout128*d_0+gout131*d_1+gout134*d_2+gout137*d_3+gout140*d_4+gout143*d_5);
            atomicAdd(vk+(i0+2)+nao*(l0+0)+2*nao2, gout144*d_0+gout147*d_1+gout150*d_2+gout153*d_3+gout156*d_4+gout159*d_5);
            atomicAdd(vk+(i0+2)+nao*(l0+1)+2*nao2, gout145*d_0+gout148*d_1+gout151*d_2+gout154*d_3+gout157*d_4+gout160*d_5);
            atomicAdd(vk+(i0+2)+nao*(l0+2)+2*nao2, gout146*d_0+gout149*d_1+gout152*d_2+gout155*d_3+gout158*d_4+gout161*d_5);
            // ijkl, jl -> ik
            d_0 = dm[(j0+0)+nao*(l0+0)];
            d_1 = dm[(j0+0)+nao*(l0+1)];
            d_2 = dm[(j0+0)+nao*(l0+2)];
            atomicAdd(vk+(i0+0)+nao*(k0+0), gout0*d_0+gout1*d_1+gout2*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+1), gout3*d_0+gout4*d_1+gout5*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+2), gout6*d_0+gout7*d_1+gout8*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+3), gout9*d_0+gout10*d_1+gout11*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+4), gout12*d_0+gout13*d_1+gout14*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+5), gout15*d_0+gout16*d_1+gout17*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+0), gout18*d_0+gout19*d_1+gout20*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+1), gout21*d_0+gout22*d_1+gout23*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+2), gout24*d_0+gout25*d_1+gout26*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+3), gout27*d_0+gout28*d_1+gout29*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+4), gout30*d_0+gout31*d_1+gout32*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+5), gout33*d_0+gout34*d_1+gout35*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+0), gout36*d_0+gout37*d_1+gout38*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+1), gout39*d_0+gout40*d_1+gout41*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+2), gout42*d_0+gout43*d_1+gout44*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+3), gout45*d_0+gout46*d_1+gout47*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+4), gout48*d_0+gout49*d_1+gout50*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+5), gout51*d_0+gout52*d_1+gout53*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+0)+nao2, gout54*d_0+gout55*d_1+gout56*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+1)+nao2, gout57*d_0+gout58*d_1+gout59*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+2)+nao2, gout60*d_0+gout61*d_1+gout62*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+3)+nao2, gout63*d_0+gout64*d_1+gout65*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+4)+nao2, gout66*d_0+gout67*d_1+gout68*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+5)+nao2, gout69*d_0+gout70*d_1+gout71*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+0)+nao2, gout72*d_0+gout73*d_1+gout74*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+1)+nao2, gout75*d_0+gout76*d_1+gout77*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+2)+nao2, gout78*d_0+gout79*d_1+gout80*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+3)+nao2, gout81*d_0+gout82*d_1+gout83*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+4)+nao2, gout84*d_0+gout85*d_1+gout86*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+5)+nao2, gout87*d_0+gout88*d_1+gout89*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+0)+nao2, gout90*d_0+gout91*d_1+gout92*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+1)+nao2, gout93*d_0+gout94*d_1+gout95*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+2)+nao2, gout96*d_0+gout97*d_1+gout98*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+3)+nao2, gout99*d_0+gout100*d_1+gout101*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+4)+nao2, gout102*d_0+gout103*d_1+gout104*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+5)+nao2, gout105*d_0+gout106*d_1+gout107*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+0)+2*nao2, gout108*d_0+gout109*d_1+gout110*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+1)+2*nao2, gout111*d_0+gout112*d_1+gout113*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+2)+2*nao2, gout114*d_0+gout115*d_1+gout116*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+3)+2*nao2, gout117*d_0+gout118*d_1+gout119*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+4)+2*nao2, gout120*d_0+gout121*d_1+gout122*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+5)+2*nao2, gout123*d_0+gout124*d_1+gout125*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+0)+2*nao2, gout126*d_0+gout127*d_1+gout128*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+1)+2*nao2, gout129*d_0+gout130*d_1+gout131*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+2)+2*nao2, gout132*d_0+gout133*d_1+gout134*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+3)+2*nao2, gout135*d_0+gout136*d_1+gout137*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+4)+2*nao2, gout138*d_0+gout139*d_1+gout140*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+5)+2*nao2, gout141*d_0+gout142*d_1+gout143*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+0)+2*nao2, gout144*d_0+gout145*d_1+gout146*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+1)+2*nao2, gout147*d_0+gout148*d_1+gout149*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+2)+2*nao2, gout150*d_0+gout151*d_1+gout152*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+3)+2*nao2, gout153*d_0+gout154*d_1+gout155*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+4)+2*nao2, gout156*d_0+gout157*d_1+gout158*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+5)+2*nao2, gout159*d_0+gout160*d_1+gout161*d_2);
            // ijkl, ik -> jl
            d_0 = dm[(i0+0)+nao*(k0+0)];
            d_1 = dm[(i0+0)+nao*(k0+1)];
            d_2 = dm[(i0+0)+nao*(k0+2)];
            d_3 = dm[(i0+0)+nao*(k0+3)];
            d_4 = dm[(i0+0)+nao*(k0+4)];
            d_5 = dm[(i0+0)+nao*(k0+5)];
            d_6 = dm[(i0+1)+nao*(k0+0)];
            d_7 = dm[(i0+1)+nao*(k0+1)];
            d_8 = dm[(i0+1)+nao*(k0+2)];
            d_9 = dm[(i0+1)+nao*(k0+3)];
            d_10 = dm[(i0+1)+nao*(k0+4)];
            d_11 = dm[(i0+1)+nao*(k0+5)];
            d_12 = dm[(i0+2)+nao*(k0+0)];
            d_13 = dm[(i0+2)+nao*(k0+1)];
            d_14 = dm[(i0+2)+nao*(k0+2)];
            d_15 = dm[(i0+2)+nao*(k0+3)];
            d_16 = dm[(i0+2)+nao*(k0+4)];
            d_17 = dm[(i0+2)+nao*(k0+5)];
            atomicAdd(vk+(j0+0)+nao*(l0+0), gout162*d_0+gout165*d_1+gout168*d_2+gout171*d_3+gout174*d_4+gout177*d_5+gout180*d_6+gout183*d_7+gout186*d_8+gout189*d_9+gout192*d_10+gout195*d_11+gout198*d_12+gout201*d_13+gout204*d_14+gout207*d_15+gout210*d_16+gout213*d_17);
            atomicAdd(vk+(j0+0)+nao*(l0+1), gout163*d_0+gout166*d_1+gout169*d_2+gout172*d_3+gout175*d_4+gout178*d_5+gout181*d_6+gout184*d_7+gout187*d_8+gout190*d_9+gout193*d_10+gout196*d_11+gout199*d_12+gout202*d_13+gout205*d_14+gout208*d_15+gout211*d_16+gout214*d_17);
            atomicAdd(vk+(j0+0)+nao*(l0+2), gout164*d_0+gout167*d_1+gout170*d_2+gout173*d_3+gout176*d_4+gout179*d_5+gout182*d_6+gout185*d_7+gout188*d_8+gout191*d_9+gout194*d_10+gout197*d_11+gout200*d_12+gout203*d_13+gout206*d_14+gout209*d_15+gout212*d_16+gout215*d_17);
            atomicAdd(vk+(j0+0)+nao*(l0+0)+nao2, gout216*d_0+gout219*d_1+gout222*d_2+gout225*d_3+gout228*d_4+gout231*d_5+gout234*d_6+gout237*d_7+gout240*d_8+gout243*d_9+gout246*d_10+gout249*d_11+gout252*d_12+gout255*d_13+gout258*d_14+gout261*d_15+gout264*d_16+gout267*d_17);
            atomicAdd(vk+(j0+0)+nao*(l0+1)+nao2, gout217*d_0+gout220*d_1+gout223*d_2+gout226*d_3+gout229*d_4+gout232*d_5+gout235*d_6+gout238*d_7+gout241*d_8+gout244*d_9+gout247*d_10+gout250*d_11+gout253*d_12+gout256*d_13+gout259*d_14+gout262*d_15+gout265*d_16+gout268*d_17);
            atomicAdd(vk+(j0+0)+nao*(l0+2)+nao2, gout218*d_0+gout221*d_1+gout224*d_2+gout227*d_3+gout230*d_4+gout233*d_5+gout236*d_6+gout239*d_7+gout242*d_8+gout245*d_9+gout248*d_10+gout251*d_11+gout254*d_12+gout257*d_13+gout260*d_14+gout263*d_15+gout266*d_16+gout269*d_17);
            atomicAdd(vk+(j0+0)+nao*(l0+0)+2*nao2, gout270*d_0+gout273*d_1+gout276*d_2+gout279*d_3+gout282*d_4+gout285*d_5+gout288*d_6+gout291*d_7+gout294*d_8+gout297*d_9+gout300*d_10+gout303*d_11+gout306*d_12+gout309*d_13+gout312*d_14+gout315*d_15+gout318*d_16+gout321*d_17);
            atomicAdd(vk+(j0+0)+nao*(l0+1)+2*nao2, gout271*d_0+gout274*d_1+gout277*d_2+gout280*d_3+gout283*d_4+gout286*d_5+gout289*d_6+gout292*d_7+gout295*d_8+gout298*d_9+gout301*d_10+gout304*d_11+gout307*d_12+gout310*d_13+gout313*d_14+gout316*d_15+gout319*d_16+gout322*d_17);
            atomicAdd(vk+(j0+0)+nao*(l0+2)+2*nao2, gout272*d_0+gout275*d_1+gout278*d_2+gout281*d_3+gout284*d_4+gout287*d_5+gout290*d_6+gout293*d_7+gout296*d_8+gout299*d_9+gout302*d_10+gout305*d_11+gout308*d_12+gout311*d_13+gout314*d_14+gout317*d_15+gout320*d_16+gout323*d_17);
            // ijkl, il -> jk
            d_0 = dm[(i0+0)+nao*(l0+0)];
            d_1 = dm[(i0+0)+nao*(l0+1)];
            d_2 = dm[(i0+0)+nao*(l0+2)];
            d_3 = dm[(i0+1)+nao*(l0+0)];
            d_4 = dm[(i0+1)+nao*(l0+1)];
            d_5 = dm[(i0+1)+nao*(l0+2)];
            d_6 = dm[(i0+2)+nao*(l0+0)];
            d_7 = dm[(i0+2)+nao*(l0+1)];
            d_8 = dm[(i0+2)+nao*(l0+2)];
            atomicAdd(vk+(j0+0)+nao*(k0+0), gout162*d_0+gout163*d_1+gout164*d_2+gout180*d_3+gout181*d_4+gout182*d_5+gout198*d_6+gout199*d_7+gout200*d_8);
            atomicAdd(vk+(j0+0)+nao*(k0+1), gout165*d_0+gout166*d_1+gout167*d_2+gout183*d_3+gout184*d_4+gout185*d_5+gout201*d_6+gout202*d_7+gout203*d_8);
            atomicAdd(vk+(j0+0)+nao*(k0+2), gout168*d_0+gout169*d_1+gout170*d_2+gout186*d_3+gout187*d_4+gout188*d_5+gout204*d_6+gout205*d_7+gout206*d_8);
            atomicAdd(vk+(j0+0)+nao*(k0+3), gout171*d_0+gout172*d_1+gout173*d_2+gout189*d_3+gout190*d_4+gout191*d_5+gout207*d_6+gout208*d_7+gout209*d_8);
            atomicAdd(vk+(j0+0)+nao*(k0+4), gout174*d_0+gout175*d_1+gout176*d_2+gout192*d_3+gout193*d_4+gout194*d_5+gout210*d_6+gout211*d_7+gout212*d_8);
            atomicAdd(vk+(j0+0)+nao*(k0+5), gout177*d_0+gout178*d_1+gout179*d_2+gout195*d_3+gout196*d_4+gout197*d_5+gout213*d_6+gout214*d_7+gout215*d_8);
            atomicAdd(vk+(j0+0)+nao*(k0+0)+nao2, gout216*d_0+gout217*d_1+gout218*d_2+gout234*d_3+gout235*d_4+gout236*d_5+gout252*d_6+gout253*d_7+gout254*d_8);
            atomicAdd(vk+(j0+0)+nao*(k0+1)+nao2, gout219*d_0+gout220*d_1+gout221*d_2+gout237*d_3+gout238*d_4+gout239*d_5+gout255*d_6+gout256*d_7+gout257*d_8);
            atomicAdd(vk+(j0+0)+nao*(k0+2)+nao2, gout222*d_0+gout223*d_1+gout224*d_2+gout240*d_3+gout241*d_4+gout242*d_5+gout258*d_6+gout259*d_7+gout260*d_8);
            atomicAdd(vk+(j0+0)+nao*(k0+3)+nao2, gout225*d_0+gout226*d_1+gout227*d_2+gout243*d_3+gout244*d_4+gout245*d_5+gout261*d_6+gout262*d_7+gout263*d_8);
            atomicAdd(vk+(j0+0)+nao*(k0+4)+nao2, gout228*d_0+gout229*d_1+gout230*d_2+gout246*d_3+gout247*d_4+gout248*d_5+gout264*d_6+gout265*d_7+gout266*d_8);
            atomicAdd(vk+(j0+0)+nao*(k0+5)+nao2, gout231*d_0+gout232*d_1+gout233*d_2+gout249*d_3+gout250*d_4+gout251*d_5+gout267*d_6+gout268*d_7+gout269*d_8);
            atomicAdd(vk+(j0+0)+nao*(k0+0)+2*nao2, gout270*d_0+gout271*d_1+gout272*d_2+gout288*d_3+gout289*d_4+gout290*d_5+gout306*d_6+gout307*d_7+gout308*d_8);
            atomicAdd(vk+(j0+0)+nao*(k0+1)+2*nao2, gout273*d_0+gout274*d_1+gout275*d_2+gout291*d_3+gout292*d_4+gout293*d_5+gout309*d_6+gout310*d_7+gout311*d_8);
            atomicAdd(vk+(j0+0)+nao*(k0+2)+2*nao2, gout276*d_0+gout277*d_1+gout278*d_2+gout294*d_3+gout295*d_4+gout296*d_5+gout312*d_6+gout313*d_7+gout314*d_8);
            atomicAdd(vk+(j0+0)+nao*(k0+3)+2*nao2, gout279*d_0+gout280*d_1+gout281*d_2+gout297*d_3+gout298*d_4+gout299*d_5+gout315*d_6+gout316*d_7+gout317*d_8);
            atomicAdd(vk+(j0+0)+nao*(k0+4)+2*nao2, gout282*d_0+gout283*d_1+gout284*d_2+gout300*d_3+gout301*d_4+gout302*d_5+gout318*d_6+gout319*d_7+gout320*d_8);
            atomicAdd(vk+(j0+0)+nao*(k0+5)+2*nao2, gout285*d_0+gout286*d_1+gout287*d_2+gout303*d_3+gout304*d_4+gout305*d_5+gout321*d_6+gout322*d_7+gout323*d_8);
            vk += 3*nao2;
        }
        dm += nao2;
    }
}

__global__
static void GINTint2e_ip1_jk_kernel_1030(GINTEnvVars envs, JKMatrix jk,
                                    BasisProdOffsets offsets)
{
    int ntasks_ij = offsets.ntasks_ij;
    int ntasks_kl = offsets.ntasks_kl;
    int task_ij = blockIdx.x * blockDim.x + threadIdx.x;
    int task_kl = blockIdx.y * blockDim.y + threadIdx.y;
    if (task_ij >= ntasks_ij || task_kl >= ntasks_kl) {
        return;
    }
    int bas_ij = offsets.bas_ij + task_ij;
    int bas_kl = offsets.bas_kl + task_kl;
    double norm = envs.fac;
    double omega = envs.omega;
    int *bas_pair2bra = c_bpcache.bas_pair2bra;
    int *bas_pair2ket = c_bpcache.bas_pair2ket;
    int ish = bas_pair2bra[bas_ij];
    int jsh = bas_pair2ket[bas_ij];
    int ksh = bas_pair2bra[bas_kl];
    int lsh = bas_pair2ket[bas_kl];
    int nprim_ij = envs.nprim_ij;
    int nprim_kl = envs.nprim_kl;
    int prim_ij = offsets.primitive_ij + task_ij * nprim_ij;
    int prim_kl = offsets.primitive_kl + task_kl * nprim_kl;

    double* __restrict__ a12 = c_bpcache.a12;
    double* __restrict__ e12 = c_bpcache.e12;
    double* __restrict__ x12 = c_bpcache.x12;
    double* __restrict__ y12 = c_bpcache.y12;
    double* __restrict__ z12 = c_bpcache.z12;
    double * __restrict__ i_exponent = c_bpcache.a1;
    double * __restrict__ j_exponent = c_bpcache.a2;

    int ij, kl;
    int prim_ij0, prim_ij1, prim_kl0, prim_kl1;
    int nbas = c_bpcache.nbas;
    double* __restrict__ bas_x = c_bpcache.bas_coords;
    double* __restrict__ bas_y = bas_x + nbas;
    double* __restrict__ bas_z = bas_y + nbas;

    double gout0 = 0;
    double gout1 = 0;
    double gout2 = 0;
    double gout3 = 0;
    double gout4 = 0;
    double gout5 = 0;
    double gout6 = 0;
    double gout7 = 0;
    double gout8 = 0;
    double gout9 = 0;
    double gout10 = 0;
    double gout11 = 0;
    double gout12 = 0;
    double gout13 = 0;
    double gout14 = 0;
    double gout15 = 0;
    double gout16 = 0;
    double gout17 = 0;
    double gout18 = 0;
    double gout19 = 0;
    double gout20 = 0;
    double gout21 = 0;
    double gout22 = 0;
    double gout23 = 0;
    double gout24 = 0;
    double gout25 = 0;
    double gout26 = 0;
    double gout27 = 0;
    double gout28 = 0;
    double gout29 = 0;
    double gout30 = 0;
    double gout31 = 0;
    double gout32 = 0;
    double gout33 = 0;
    double gout34 = 0;
    double gout35 = 0;
    double gout36 = 0;
    double gout37 = 0;
    double gout38 = 0;
    double gout39 = 0;
    double gout40 = 0;
    double gout41 = 0;
    double gout42 = 0;
    double gout43 = 0;
    double gout44 = 0;
    double gout45 = 0;
    double gout46 = 0;
    double gout47 = 0;
    double gout48 = 0;
    double gout49 = 0;
    double gout50 = 0;
    double gout51 = 0;
    double gout52 = 0;
    double gout53 = 0;
    double gout54 = 0;
    double gout55 = 0;
    double gout56 = 0;
    double gout57 = 0;
    double gout58 = 0;
    double gout59 = 0;
    double gout60 = 0;
    double gout61 = 0;
    double gout62 = 0;
    double gout63 = 0;
    double gout64 = 0;
    double gout65 = 0;
    double gout66 = 0;
    double gout67 = 0;
    double gout68 = 0;
    double gout69 = 0;
    double gout70 = 0;
    double gout71 = 0;
    double gout72 = 0;
    double gout73 = 0;
    double gout74 = 0;
    double gout75 = 0;
    double gout76 = 0;
    double gout77 = 0;
    double gout78 = 0;
    double gout79 = 0;
    double gout80 = 0;
    double gout81 = 0;
    double gout82 = 0;
    double gout83 = 0;
    double gout84 = 0;
    double gout85 = 0;
    double gout86 = 0;
    double gout87 = 0;
    double gout88 = 0;
    double gout89 = 0;
    double gout90 = 0;
    double gout91 = 0;
    double gout92 = 0;
    double gout93 = 0;
    double gout94 = 0;
    double gout95 = 0;
    double gout96 = 0;
    double gout97 = 0;
    double gout98 = 0;
    double gout99 = 0;
    double gout100 = 0;
    double gout101 = 0;
    double gout102 = 0;
    double gout103 = 0;
    double gout104 = 0;
    double gout105 = 0;
    double gout106 = 0;
    double gout107 = 0;
    double gout108 = 0;
    double gout109 = 0;
    double gout110 = 0;
    double gout111 = 0;
    double gout112 = 0;
    double gout113 = 0;
    double gout114 = 0;
    double gout115 = 0;
    double gout116 = 0;
    double gout117 = 0;
    double gout118 = 0;
    double gout119 = 0;
    double gout120 = 0;
    double gout121 = 0;
    double gout122 = 0;
    double gout123 = 0;
    double gout124 = 0;
    double gout125 = 0;
    double gout126 = 0;
    double gout127 = 0;
    double gout128 = 0;
    double gout129 = 0;
    double gout130 = 0;
    double gout131 = 0;
    double gout132 = 0;
    double gout133 = 0;
    double gout134 = 0;
    double gout135 = 0;
    double gout136 = 0;
    double gout137 = 0;
    double gout138 = 0;
    double gout139 = 0;
    double gout140 = 0;
    double gout141 = 0;
    double gout142 = 0;
    double gout143 = 0;
    double gout144 = 0;
    double gout145 = 0;
    double gout146 = 0;
    double gout147 = 0;
    double gout148 = 0;
    double gout149 = 0;
    double gout150 = 0;
    double gout151 = 0;
    double gout152 = 0;
    double gout153 = 0;
    double gout154 = 0;
    double gout155 = 0;
    double gout156 = 0;
    double gout157 = 0;
    double gout158 = 0;
    double gout159 = 0;
    double gout160 = 0;
    double gout161 = 0;
    double gout162 = 0;
    double gout163 = 0;
    double gout164 = 0;
    double gout165 = 0;
    double gout166 = 0;
    double gout167 = 0;
    double gout168 = 0;
    double gout169 = 0;
    double gout170 = 0;
    double gout171 = 0;
    double gout172 = 0;
    double gout173 = 0;
    double gout174 = 0;
    double gout175 = 0;
    double gout176 = 0;
    double gout177 = 0;
    double gout178 = 0;
    double gout179 = 0;

    double xi = bas_x[ish];
    double yi = bas_y[ish];
    double zi = bas_z[ish];
    double ABx = xi - bas_x[jsh];
    double ABy = yi - bas_y[jsh];
    double ABz = zi - bas_z[jsh];
    double xk = bas_x[ksh];
    double yk = bas_y[ksh];
    double zk = bas_z[ksh];

    prim_ij0 = prim_ij;
    prim_ij1 = prim_ij + nprim_ij;
    prim_kl0 = prim_kl;
    prim_kl1 = prim_kl + nprim_kl;
    double rw[6];
    int irys;
    for (ij = prim_ij0; ij < prim_ij1; ++ij) {
        double alpha = i_exponent[ij];
        double beta = j_exponent[ij];
        double aij = a12[ij];
        double eij = e12[ij];
        double xij = x12[ij];
        double yij = y12[ij];
        double zij = z12[ij];
    for (kl = prim_kl0; kl < prim_kl1; ++kl) {
        double akl = a12[kl];
        double ekl = e12[kl];
        double xkl = x12[kl];
        double ykl = y12[kl];
        double zkl = z12[kl];
        double xijxkl = xij - xkl;
        double yijykl = yij - ykl;
        double zijzkl = zij - zkl;
        double aijkl = aij + akl;
        double a1 = aij * akl;
        double a0 = a1 / aijkl;
        double theta = omega > 0.0 ? omega * omega / (omega * omega + a0) : 1.0; 
        a0 *= theta;
        double x = a0 * (xijxkl * xijxkl + yijykl * yijykl + zijzkl * zijzkl);
        double fac = norm * eij * ekl * sqrt(a0 / (a1 * a1 * a1));
        //double fac = norm * eij * ekl / (sqrt(aijkl) * a1);

        GINTrys_root<3>(x, rw);
        GINTscale_u<3>(rw, theta);
      for (irys = 0; irys < 3; ++irys) {
            double weight0 = rw[irys+3] * fac;
            double root0 = rw[irys];
            double u2 = a0 * root0;
            double tmp4 = .5 / (u2 * aijkl + a1);
            double B00 = u2 * tmp4;
            double tmp1 = 2 * B00;
            double B10 = B00 + tmp4 * akl;
            double tmp2 = tmp1 * akl;
            double C00x = xij - xi - tmp2 * xijxkl;
            double C00y = yij - yi - tmp2 * yijykl;
            double C00z = zij - zi - tmp2 * zijzkl;
            double B01 = B00 + tmp4 * aij;
            double tmp3 = tmp1 * aij;
            double D00x = xkl - xk + tmp3 * xijxkl;
            double D00y = ykl - yk + tmp3 * yijykl;
            double D00z = zkl - zk + tmp3 * zijzkl;

            double g0 = B10+C00x*C00x;
            double g1 = C00x*D00x;
            double g2 = B00+g1;
            double g3 = 2*B00*C00x;
            double g4 = g0*D00x;
            double g5 = g3+g4;
            double g6 = B01+D00x*D00x;
            double g7 = 2*B00*D00x;
            double g8 = C00x*g6;
            double g9 = g7+g8;
            double g10 = 2*B00*B00;
            double g11 = 4*B00*C00x*D00x;
            double g12 = g0*g6;
            double g13 = g10+g11+g12;
            double g15 = (3*B01*D00x)+D00x*D00x*D00x;
            double g16 = 3*B00*g6;
            double g17 = 3*B01;
            double g18 = g17+D00x*D00x;
            double g20 = g16+(C00x*D00x*g18);
            double g21 = 6*B00*B00*D00x;
            double g22 = 6*B00*C00x*g6;
            double g23 = g0*D00x*g18;
            double g24 = g21+g22+g23;
            double g25 = ABx+C00x;
            double g27 = B10+(C00x*g25);
            double g29 = B00+(g25*D00x);
            double g31 = ABx+(2*C00x);
            double g34 = (B00*g31)+(g27*D00x);
            double g36 = g7+(g25*g6);
            double g39 = g10+(2*B00*g31*D00x)+(g27*g6);
            double g41 = g16+(g25*D00x*g18);
            double g44 = g21+(3*ABx*B00*g6)+g22+(ABx*C00x*D00x*g18)+g23;
            double g45 = B10+C00y*C00y;
            double g47 = B00+(C00y*D00y);
            double g50 = (2*B00*C00y)+(g45*D00y);
            double g51 = B01+D00y*D00y;
            double g52 = 2*B00*D00y;
            double g54 = g52+(C00y*g51);
            double g57 = g10+(4*B00*C00y*D00y)+(g45*g51);
            double g59 = (3*B01*D00y)+D00y*D00y*D00y;
            double g60 = 3*B00*g51;
            double g61 = g17+D00y*D00y;
            double g63 = g60+(C00y*D00y*g61);
            double g64 = 6*B00*B00*D00y;
            double g65 = 6*B00*C00y*g51;
            double g66 = g45*D00y*g61;
            double g67 = g64+g65+g66;
            double g68 = ABy+C00y;
            double g70 = B10+(C00y*g68);
            double g72 = B00+(g68*D00y);
            double g74 = ABy+(2*C00y);
            double g77 = (B00*g74)+(g70*D00y);
            double g79 = g52+(g68*g51);
            double g82 = g10+(2*B00*g74*D00y)+(g70*g51);
            double g84 = g60+(g68*D00y*g61);
            double g87 = g64+(3*ABy*B00*g51)+g65+(ABy*C00y*D00y*g61)+g66;
            double g88 = B10+C00z*C00z;
            double g90 = B00+(C00z*D00z);
            double g93 = (2*B00*C00z)+(g88*D00z);
            double g94 = B01+D00z*D00z;
            double g95 = 2*B00*D00z;
            double g97 = g95+(C00z*g94);
            double g100 = g10+(4*B00*C00z*D00z)+(g88*g94);
            double g102 = (3*B01*D00z)+D00z*D00z*D00z;
            double g103 = 3*B00*g94;
            double g104 = g17+D00z*D00z;
            double g106 = g103+(C00z*D00z*g104);
            double g107 = 6*B00*B00*D00z;
            double g108 = 6*B00*C00z*g94;
            double g109 = g88*D00z*g104;
            double g110 = g107+g108+g109;
            double g111 = ABz+C00z;
            double g113 = B10+(C00z*g111);
            double g115 = B00+(g111*D00z);
            double g117 = ABz+(2*C00z);
            double g120 = (B00*g117)+(g113*D00z);
            double g122 = g95+(g111*g94);
            double g125 = g10+(2*B00*g117*D00z)+(g113*g94);
            double g127 = g103+(g111*D00z*g104);
            double g130 = g107+(3*ABz*B00*g94)+g108+(ABz*C00z*D00z*g104)+g109;

            gout0 += (-g15 + 2*alpha*g24) * weight0;
            gout1 += (-g6 + 2*alpha*g13) * (D00y) * weight0;
            gout2 += (-g6 + 2*alpha*g13) * (D00z) * weight0;
            gout3 += (-D00x + 2*alpha*g5) * (g51) * weight0;
            gout4 += (-D00x + 2*alpha*g5) * (D00y) * (D00z) * weight0;
            gout5 += (-D00x + 2*alpha*g5) * (g94) * weight0;
            gout6 += (-1 + 2*alpha*g0) * (g59) * weight0;
            gout7 += (-1 + 2*alpha*g0) * (g51) * (D00z) * weight0;
            gout8 += (-1 + 2*alpha*g0) * (D00y) * (g94) * weight0;
            gout9 += (-1 + 2*alpha*g0) * (g102) * weight0;
            gout10 += (2*alpha*g20) * (C00y) * weight0;
            gout11 += (2*alpha*g9) * (g47) * weight0;
            gout12 += (2*alpha*g9) * (C00y) * (D00z) * weight0;
            gout13 += (2*alpha*g2) * (g54) * weight0;
            gout14 += (2*alpha*g2) * (g47) * (D00z) * weight0;
            gout15 += (2*alpha*g2) * (C00y) * (g94) * weight0;
            gout16 += (2*alpha*C00x) * (g63) * weight0;
            gout17 += (2*alpha*C00x) * (g54) * (D00z) * weight0;
            gout18 += (2*alpha*C00x) * (g47) * (g94) * weight0;
            gout19 += (2*alpha*C00x) * (C00y) * (g102) * weight0;
            gout20 += (2*alpha*g20) * (C00z) * weight0;
            gout21 += (2*alpha*g9) * (D00y) * (C00z) * weight0;
            gout22 += (2*alpha*g9) * (g90) * weight0;
            gout23 += (2*alpha*g2) * (g51) * (C00z) * weight0;
            gout24 += (2*alpha*g2) * (D00y) * (g90) * weight0;
            gout25 += (2*alpha*g2) * (g97) * weight0;
            gout26 += (2*alpha*C00x) * (g59) * (C00z) * weight0;
            gout27 += (2*alpha*C00x) * (g51) * (g90) * weight0;
            gout28 += (2*alpha*C00x) * (D00y) * (g97) * weight0;
            gout29 += (2*alpha*C00x) * (g106) * weight0;
            gout30 += (g20) * (2*alpha*C00y) * weight0;
            gout31 += (g9) * (2*alpha*g47) * weight0;
            gout32 += (g9) * (2*alpha*C00y) * (D00z) * weight0;
            gout33 += (g2) * (2*alpha*g54) * weight0;
            gout34 += (g2) * (2*alpha*g47) * (D00z) * weight0;
            gout35 += (g2) * (2*alpha*C00y) * (g94) * weight0;
            gout36 += (C00x) * (2*alpha*g63) * weight0;
            gout37 += (C00x) * (2*alpha*g54) * (D00z) * weight0;
            gout38 += (C00x) * (2*alpha*g47) * (g94) * weight0;
            gout39 += (C00x) * (2*alpha*C00y) * (g102) * weight0;
            gout40 += (g15) * (-1 + 2*alpha*g45) * weight0;
            gout41 += (g6) * (-D00y + 2*alpha*g50) * weight0;
            gout42 += (g6) * (-1 + 2*alpha*g45) * (D00z) * weight0;
            gout43 += (D00x) * (-g51 + 2*alpha*g57) * weight0;
            gout44 += (D00x) * (-D00y + 2*alpha*g50) * (D00z) * weight0;
            gout45 += (D00x) * (-1 + 2*alpha*g45) * (g94) * weight0;
            gout46 += (-g59 + 2*alpha*g67) * weight0;
            gout47 += (-g51 + 2*alpha*g57) * (D00z) * weight0;
            gout48 += (-D00y + 2*alpha*g50) * (g94) * weight0;
            gout49 += (-1 + 2*alpha*g45) * (g102) * weight0;
            gout50 += (g15) * (2*alpha*C00y) * (C00z) * weight0;
            gout51 += (g6) * (2*alpha*g47) * (C00z) * weight0;
            gout52 += (g6) * (2*alpha*C00y) * (g90) * weight0;
            gout53 += (D00x) * (2*alpha*g54) * (C00z) * weight0;
            gout54 += (D00x) * (2*alpha*g47) * (g90) * weight0;
            gout55 += (D00x) * (2*alpha*C00y) * (g97) * weight0;
            gout56 += (2*alpha*g63) * (C00z) * weight0;
            gout57 += (2*alpha*g54) * (g90) * weight0;
            gout58 += (2*alpha*g47) * (g97) * weight0;
            gout59 += (2*alpha*C00y) * (g106) * weight0;
            gout60 += (g20) * (2*alpha*C00z) * weight0;
            gout61 += (g9) * (D00y) * (2*alpha*C00z) * weight0;
            gout62 += (g9) * (2*alpha*g90) * weight0;
            gout63 += (g2) * (g51) * (2*alpha*C00z) * weight0;
            gout64 += (g2) * (D00y) * (2*alpha*g90) * weight0;
            gout65 += (g2) * (2*alpha*g97) * weight0;
            gout66 += (C00x) * (g59) * (2*alpha*C00z) * weight0;
            gout67 += (C00x) * (g51) * (2*alpha*g90) * weight0;
            gout68 += (C00x) * (D00y) * (2*alpha*g97) * weight0;
            gout69 += (C00x) * (2*alpha*g106) * weight0;
            gout70 += (g15) * (C00y) * (2*alpha*C00z) * weight0;
            gout71 += (g6) * (g47) * (2*alpha*C00z) * weight0;
            gout72 += (g6) * (C00y) * (2*alpha*g90) * weight0;
            gout73 += (D00x) * (g54) * (2*alpha*C00z) * weight0;
            gout74 += (D00x) * (g47) * (2*alpha*g90) * weight0;
            gout75 += (D00x) * (C00y) * (2*alpha*g97) * weight0;
            gout76 += (g63) * (2*alpha*C00z) * weight0;
            gout77 += (g54) * (2*alpha*g90) * weight0;
            gout78 += (g47) * (2*alpha*g97) * weight0;
            gout79 += (C00y) * (2*alpha*g106) * weight0;
            gout80 += (g15) * (-1 + 2*alpha*g88) * weight0;
            gout81 += (g6) * (D00y) * (-1 + 2*alpha*g88) * weight0;
            gout82 += (g6) * (-D00z + 2*alpha*g93) * weight0;
            gout83 += (D00x) * (g51) * (-1 + 2*alpha*g88) * weight0;
            gout84 += (D00x) * (D00y) * (-D00z + 2*alpha*g93) * weight0;
            gout85 += (D00x) * (-g94 + 2*alpha*g100) * weight0;
            gout86 += (g59) * (-1 + 2*alpha*g88) * weight0;
            gout87 += (g51) * (-D00z + 2*alpha*g93) * weight0;
            gout88 += (D00y) * (-g94 + 2*alpha*g100) * weight0;
            gout89 += (-g102 + 2*alpha*g110) * weight0;
            gout90 += (2*beta*g44) * weight0;
            gout91 += (2*beta*g39) * (D00y) * weight0;
            gout92 += (2*beta*g39) * (D00z) * weight0;
            gout93 += (2*beta*g34) * (g51) * weight0;
            gout94 += (2*beta*g34) * (D00y) * (D00z) * weight0;
            gout95 += (2*beta*g34) * (g94) * weight0;
            gout96 += (2*beta*g27) * (g59) * weight0;
            gout97 += (2*beta*g27) * (g51) * (D00z) * weight0;
            gout98 += (2*beta*g27) * (D00y) * (g94) * weight0;
            gout99 += (2*beta*g27) * (g102) * weight0;
            gout100 += (2*beta*g41) * (C00y) * weight0;
            gout101 += (2*beta*g36) * (g47) * weight0;
            gout102 += (2*beta*g36) * (C00y) * (D00z) * weight0;
            gout103 += (2*beta*g29) * (g54) * weight0;
            gout104 += (2*beta*g29) * (g47) * (D00z) * weight0;
            gout105 += (2*beta*g29) * (C00y) * (g94) * weight0;
            gout106 += (2*beta*g25) * (g63) * weight0;
            gout107 += (2*beta*g25) * (g54) * (D00z) * weight0;
            gout108 += (2*beta*g25) * (g47) * (g94) * weight0;
            gout109 += (2*beta*g25) * (C00y) * (g102) * weight0;
            gout110 += (2*beta*g41) * (C00z) * weight0;
            gout111 += (2*beta*g36) * (D00y) * (C00z) * weight0;
            gout112 += (2*beta*g36) * (g90) * weight0;
            gout113 += (2*beta*g29) * (g51) * (C00z) * weight0;
            gout114 += (2*beta*g29) * (D00y) * (g90) * weight0;
            gout115 += (2*beta*g29) * (g97) * weight0;
            gout116 += (2*beta*g25) * (g59) * (C00z) * weight0;
            gout117 += (2*beta*g25) * (g51) * (g90) * weight0;
            gout118 += (2*beta*g25) * (D00y) * (g97) * weight0;
            gout119 += (2*beta*g25) * (g106) * weight0;
            gout120 += (g20) * (2*beta*g68) * weight0;
            gout121 += (g9) * (2*beta*g72) * weight0;
            gout122 += (g9) * (2*beta*g68) * (D00z) * weight0;
            gout123 += (g2) * (2*beta*g79) * weight0;
            gout124 += (g2) * (2*beta*g72) * (D00z) * weight0;
            gout125 += (g2) * (2*beta*g68) * (g94) * weight0;
            gout126 += (C00x) * (2*beta*g84) * weight0;
            gout127 += (C00x) * (2*beta*g79) * (D00z) * weight0;
            gout128 += (C00x) * (2*beta*g72) * (g94) * weight0;
            gout129 += (C00x) * (2*beta*g68) * (g102) * weight0;
            gout130 += (g15) * (2*beta*g70) * weight0;
            gout131 += (g6) * (2*beta*g77) * weight0;
            gout132 += (g6) * (2*beta*g70) * (D00z) * weight0;
            gout133 += (D00x) * (2*beta*g82) * weight0;
            gout134 += (D00x) * (2*beta*g77) * (D00z) * weight0;
            gout135 += (D00x) * (2*beta*g70) * (g94) * weight0;
            gout136 += (2*beta*g87) * weight0;
            gout137 += (2*beta*g82) * (D00z) * weight0;
            gout138 += (2*beta*g77) * (g94) * weight0;
            gout139 += (2*beta*g70) * (g102) * weight0;
            gout140 += (g15) * (2*beta*g68) * (C00z) * weight0;
            gout141 += (g6) * (2*beta*g72) * (C00z) * weight0;
            gout142 += (g6) * (2*beta*g68) * (g90) * weight0;
            gout143 += (D00x) * (2*beta*g79) * (C00z) * weight0;
            gout144 += (D00x) * (2*beta*g72) * (g90) * weight0;
            gout145 += (D00x) * (2*beta*g68) * (g97) * weight0;
            gout146 += (2*beta*g84) * (C00z) * weight0;
            gout147 += (2*beta*g79) * (g90) * weight0;
            gout148 += (2*beta*g72) * (g97) * weight0;
            gout149 += (2*beta*g68) * (g106) * weight0;
            gout150 += (g20) * (2*beta*g111) * weight0;
            gout151 += (g9) * (D00y) * (2*beta*g111) * weight0;
            gout152 += (g9) * (2*beta*g115) * weight0;
            gout153 += (g2) * (g51) * (2*beta*g111) * weight0;
            gout154 += (g2) * (D00y) * (2*beta*g115) * weight0;
            gout155 += (g2) * (2*beta*g122) * weight0;
            gout156 += (C00x) * (g59) * (2*beta*g111) * weight0;
            gout157 += (C00x) * (g51) * (2*beta*g115) * weight0;
            gout158 += (C00x) * (D00y) * (2*beta*g122) * weight0;
            gout159 += (C00x) * (2*beta*g127) * weight0;
            gout160 += (g15) * (C00y) * (2*beta*g111) * weight0;
            gout161 += (g6) * (g47) * (2*beta*g111) * weight0;
            gout162 += (g6) * (C00y) * (2*beta*g115) * weight0;
            gout163 += (D00x) * (g54) * (2*beta*g111) * weight0;
            gout164 += (D00x) * (g47) * (2*beta*g115) * weight0;
            gout165 += (D00x) * (C00y) * (2*beta*g122) * weight0;
            gout166 += (g63) * (2*beta*g111) * weight0;
            gout167 += (g54) * (2*beta*g115) * weight0;
            gout168 += (g47) * (2*beta*g122) * weight0;
            gout169 += (C00y) * (2*beta*g127) * weight0;
            gout170 += (g15) * (2*beta*g113) * weight0;
            gout171 += (g6) * (D00y) * (2*beta*g113) * weight0;
            gout172 += (g6) * (2*beta*g120) * weight0;
            gout173 += (D00x) * (g51) * (2*beta*g113) * weight0;
            gout174 += (D00x) * (D00y) * (2*beta*g120) * weight0;
            gout175 += (D00x) * (2*beta*g125) * weight0;
            gout176 += (g59) * (2*beta*g113) * weight0;
            gout177 += (g51) * (2*beta*g120) * weight0;
            gout178 += (D00y) * (2*beta*g125) * weight0;
            gout179 += (2*beta*g130) * weight0;
        }
    } }

    int *ao_loc = c_bpcache.ao_loc;
    int i0 = ao_loc[ish];
    int j0 = ao_loc[jsh];
    int k0 = ao_loc[ksh];
    int l0 = ao_loc[lsh];
    int n_dm = jk.n_dm;
    int nao = jk.nao;
    size_t nao2 = nao * nao;
    double* __restrict__ dm = jk.dm;
    double *vj = jk.vj;
    double *vk = jk.vk;
    double d_0, d_1, d_2, d_3, d_4, d_5, d_6, d_7, d_8, d_9, d_10, d_11, d_12, d_13, d_14, d_15, d_16, d_17, d_18, d_19, d_20, d_21, d_22, d_23, d_24, d_25, d_26, d_27, d_28, d_29;

    for (int i_dm = 0; i_dm < n_dm; ++i_dm) {
        if (vj != NULL) {
            d_0 = dm[(k0+0)+nao*(l0+0)];
            d_1 = dm[(k0+1)+nao*(l0+0)];
            d_2 = dm[(k0+2)+nao*(l0+0)];
            d_3 = dm[(k0+3)+nao*(l0+0)];
            d_4 = dm[(k0+4)+nao*(l0+0)];
            d_5 = dm[(k0+5)+nao*(l0+0)];
            d_6 = dm[(k0+6)+nao*(l0+0)];
            d_7 = dm[(k0+7)+nao*(l0+0)];
            d_8 = dm[(k0+8)+nao*(l0+0)];
            d_9 = dm[(k0+9)+nao*(l0+0)];
            atomicAdd(vj+(i0+0)+nao*(j0+0), gout0*d_0+gout1*d_1+gout2*d_2+gout3*d_3+gout4*d_4+gout5*d_5+gout6*d_6+gout7*d_7+gout8*d_8+gout9*d_9);
            atomicAdd(vj+(i0+1)+nao*(j0+0), gout10*d_0+gout11*d_1+gout12*d_2+gout13*d_3+gout14*d_4+gout15*d_5+gout16*d_6+gout17*d_7+gout18*d_8+gout19*d_9);
            atomicAdd(vj+(i0+2)+nao*(j0+0), gout20*d_0+gout21*d_1+gout22*d_2+gout23*d_3+gout24*d_4+gout25*d_5+gout26*d_6+gout27*d_7+gout28*d_8+gout29*d_9);
            atomicAdd(vj+(i0+0)+nao*(j0+0)+nao2, gout30*d_0+gout31*d_1+gout32*d_2+gout33*d_3+gout34*d_4+gout35*d_5+gout36*d_6+gout37*d_7+gout38*d_8+gout39*d_9);
            atomicAdd(vj+(i0+1)+nao*(j0+0)+nao2, gout40*d_0+gout41*d_1+gout42*d_2+gout43*d_3+gout44*d_4+gout45*d_5+gout46*d_6+gout47*d_7+gout48*d_8+gout49*d_9);
            atomicAdd(vj+(i0+2)+nao*(j0+0)+nao2, gout50*d_0+gout51*d_1+gout52*d_2+gout53*d_3+gout54*d_4+gout55*d_5+gout56*d_6+gout57*d_7+gout58*d_8+gout59*d_9);
            atomicAdd(vj+(i0+0)+nao*(j0+0)+2*nao2, gout60*d_0+gout61*d_1+gout62*d_2+gout63*d_3+gout64*d_4+gout65*d_5+gout66*d_6+gout67*d_7+gout68*d_8+gout69*d_9);
            atomicAdd(vj+(i0+1)+nao*(j0+0)+2*nao2, gout70*d_0+gout71*d_1+gout72*d_2+gout73*d_3+gout74*d_4+gout75*d_5+gout76*d_6+gout77*d_7+gout78*d_8+gout79*d_9);
            atomicAdd(vj+(i0+2)+nao*(j0+0)+2*nao2, gout80*d_0+gout81*d_1+gout82*d_2+gout83*d_3+gout84*d_4+gout85*d_5+gout86*d_6+gout87*d_7+gout88*d_8+gout89*d_9);
            atomicAdd(vj+nao*(i0+0)+(j0+0), gout90*d_0+gout91*d_1+gout92*d_2+gout93*d_3+gout94*d_4+gout95*d_5+gout96*d_6+gout97*d_7+gout98*d_8+gout99*d_9);
            atomicAdd(vj+nao*(i0+1)+(j0+0), gout100*d_0+gout101*d_1+gout102*d_2+gout103*d_3+gout104*d_4+gout105*d_5+gout106*d_6+gout107*d_7+gout108*d_8+gout109*d_9);
            atomicAdd(vj+nao*(i0+2)+(j0+0), gout110*d_0+gout111*d_1+gout112*d_2+gout113*d_3+gout114*d_4+gout115*d_5+gout116*d_6+gout117*d_7+gout118*d_8+gout119*d_9);
            atomicAdd(vj+nao*(i0+0)+(j0+0)+nao2, gout120*d_0+gout121*d_1+gout122*d_2+gout123*d_3+gout124*d_4+gout125*d_5+gout126*d_6+gout127*d_7+gout128*d_8+gout129*d_9);
            atomicAdd(vj+nao*(i0+1)+(j0+0)+nao2, gout130*d_0+gout131*d_1+gout132*d_2+gout133*d_3+gout134*d_4+gout135*d_5+gout136*d_6+gout137*d_7+gout138*d_8+gout139*d_9);
            atomicAdd(vj+nao*(i0+2)+(j0+0)+nao2, gout140*d_0+gout141*d_1+gout142*d_2+gout143*d_3+gout144*d_4+gout145*d_5+gout146*d_6+gout147*d_7+gout148*d_8+gout149*d_9);
            atomicAdd(vj+nao*(i0+0)+(j0+0)+2*nao2, gout150*d_0+gout151*d_1+gout152*d_2+gout153*d_3+gout154*d_4+gout155*d_5+gout156*d_6+gout157*d_7+gout158*d_8+gout159*d_9);
            atomicAdd(vj+nao*(i0+1)+(j0+0)+2*nao2, gout160*d_0+gout161*d_1+gout162*d_2+gout163*d_3+gout164*d_4+gout165*d_5+gout166*d_6+gout167*d_7+gout168*d_8+gout169*d_9);
            atomicAdd(vj+nao*(i0+2)+(j0+0)+2*nao2, gout170*d_0+gout171*d_1+gout172*d_2+gout173*d_3+gout174*d_4+gout175*d_5+gout176*d_6+gout177*d_7+gout178*d_8+gout179*d_9);
            vj += 3*nao2;
        }
        if (vk != NULL) {
            // ijkl, jk -> il
            d_0 = dm[(j0+0)+nao*(k0+0)];
            d_1 = dm[(j0+0)+nao*(k0+1)];
            d_2 = dm[(j0+0)+nao*(k0+2)];
            d_3 = dm[(j0+0)+nao*(k0+3)];
            d_4 = dm[(j0+0)+nao*(k0+4)];
            d_5 = dm[(j0+0)+nao*(k0+5)];
            d_6 = dm[(j0+0)+nao*(k0+6)];
            d_7 = dm[(j0+0)+nao*(k0+7)];
            d_8 = dm[(j0+0)+nao*(k0+8)];
            d_9 = dm[(j0+0)+nao*(k0+9)];
            atomicAdd(vk+(i0+0)+nao*(l0+0), gout0*d_0+gout1*d_1+gout2*d_2+gout3*d_3+gout4*d_4+gout5*d_5+gout6*d_6+gout7*d_7+gout8*d_8+gout9*d_9);
            atomicAdd(vk+(i0+1)+nao*(l0+0), gout10*d_0+gout11*d_1+gout12*d_2+gout13*d_3+gout14*d_4+gout15*d_5+gout16*d_6+gout17*d_7+gout18*d_8+gout19*d_9);
            atomicAdd(vk+(i0+2)+nao*(l0+0), gout20*d_0+gout21*d_1+gout22*d_2+gout23*d_3+gout24*d_4+gout25*d_5+gout26*d_6+gout27*d_7+gout28*d_8+gout29*d_9);
            atomicAdd(vk+(i0+0)+nao*(l0+0)+nao2, gout30*d_0+gout31*d_1+gout32*d_2+gout33*d_3+gout34*d_4+gout35*d_5+gout36*d_6+gout37*d_7+gout38*d_8+gout39*d_9);
            atomicAdd(vk+(i0+1)+nao*(l0+0)+nao2, gout40*d_0+gout41*d_1+gout42*d_2+gout43*d_3+gout44*d_4+gout45*d_5+gout46*d_6+gout47*d_7+gout48*d_8+gout49*d_9);
            atomicAdd(vk+(i0+2)+nao*(l0+0)+nao2, gout50*d_0+gout51*d_1+gout52*d_2+gout53*d_3+gout54*d_4+gout55*d_5+gout56*d_6+gout57*d_7+gout58*d_8+gout59*d_9);
            atomicAdd(vk+(i0+0)+nao*(l0+0)+2*nao2, gout60*d_0+gout61*d_1+gout62*d_2+gout63*d_3+gout64*d_4+gout65*d_5+gout66*d_6+gout67*d_7+gout68*d_8+gout69*d_9);
            atomicAdd(vk+(i0+1)+nao*(l0+0)+2*nao2, gout70*d_0+gout71*d_1+gout72*d_2+gout73*d_3+gout74*d_4+gout75*d_5+gout76*d_6+gout77*d_7+gout78*d_8+gout79*d_9);
            atomicAdd(vk+(i0+2)+nao*(l0+0)+2*nao2, gout80*d_0+gout81*d_1+gout82*d_2+gout83*d_3+gout84*d_4+gout85*d_5+gout86*d_6+gout87*d_7+gout88*d_8+gout89*d_9);
            // ijkl, jl -> ik
            d_0 = dm[(j0+0)+nao*(l0+0)];
            atomicAdd(vk+(i0+0)+nao*(k0+0), gout0*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+1), gout1*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+2), gout2*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+3), gout3*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+4), gout4*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+5), gout5*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+6), gout6*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+7), gout7*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+8), gout8*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+9), gout9*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+0), gout10*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+1), gout11*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+2), gout12*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+3), gout13*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+4), gout14*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+5), gout15*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+6), gout16*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+7), gout17*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+8), gout18*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+9), gout19*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+0), gout20*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+1), gout21*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+2), gout22*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+3), gout23*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+4), gout24*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+5), gout25*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+6), gout26*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+7), gout27*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+8), gout28*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+9), gout29*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+0)+nao2, gout30*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+1)+nao2, gout31*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+2)+nao2, gout32*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+3)+nao2, gout33*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+4)+nao2, gout34*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+5)+nao2, gout35*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+6)+nao2, gout36*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+7)+nao2, gout37*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+8)+nao2, gout38*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+9)+nao2, gout39*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+0)+nao2, gout40*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+1)+nao2, gout41*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+2)+nao2, gout42*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+3)+nao2, gout43*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+4)+nao2, gout44*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+5)+nao2, gout45*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+6)+nao2, gout46*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+7)+nao2, gout47*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+8)+nao2, gout48*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+9)+nao2, gout49*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+0)+nao2, gout50*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+1)+nao2, gout51*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+2)+nao2, gout52*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+3)+nao2, gout53*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+4)+nao2, gout54*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+5)+nao2, gout55*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+6)+nao2, gout56*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+7)+nao2, gout57*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+8)+nao2, gout58*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+9)+nao2, gout59*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+0)+2*nao2, gout60*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+1)+2*nao2, gout61*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+2)+2*nao2, gout62*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+3)+2*nao2, gout63*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+4)+2*nao2, gout64*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+5)+2*nao2, gout65*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+6)+2*nao2, gout66*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+7)+2*nao2, gout67*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+8)+2*nao2, gout68*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+9)+2*nao2, gout69*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+0)+2*nao2, gout70*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+1)+2*nao2, gout71*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+2)+2*nao2, gout72*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+3)+2*nao2, gout73*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+4)+2*nao2, gout74*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+5)+2*nao2, gout75*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+6)+2*nao2, gout76*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+7)+2*nao2, gout77*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+8)+2*nao2, gout78*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+9)+2*nao2, gout79*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+0)+2*nao2, gout80*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+1)+2*nao2, gout81*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+2)+2*nao2, gout82*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+3)+2*nao2, gout83*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+4)+2*nao2, gout84*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+5)+2*nao2, gout85*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+6)+2*nao2, gout86*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+7)+2*nao2, gout87*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+8)+2*nao2, gout88*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+9)+2*nao2, gout89*d_0);
            // ijkl, ik -> jl
            d_0 = dm[(i0+0)+nao*(k0+0)];
            d_1 = dm[(i0+0)+nao*(k0+1)];
            d_2 = dm[(i0+0)+nao*(k0+2)];
            d_3 = dm[(i0+0)+nao*(k0+3)];
            d_4 = dm[(i0+0)+nao*(k0+4)];
            d_5 = dm[(i0+0)+nao*(k0+5)];
            d_6 = dm[(i0+0)+nao*(k0+6)];
            d_7 = dm[(i0+0)+nao*(k0+7)];
            d_8 = dm[(i0+0)+nao*(k0+8)];
            d_9 = dm[(i0+0)+nao*(k0+9)];
            d_10 = dm[(i0+1)+nao*(k0+0)];
            d_11 = dm[(i0+1)+nao*(k0+1)];
            d_12 = dm[(i0+1)+nao*(k0+2)];
            d_13 = dm[(i0+1)+nao*(k0+3)];
            d_14 = dm[(i0+1)+nao*(k0+4)];
            d_15 = dm[(i0+1)+nao*(k0+5)];
            d_16 = dm[(i0+1)+nao*(k0+6)];
            d_17 = dm[(i0+1)+nao*(k0+7)];
            d_18 = dm[(i0+1)+nao*(k0+8)];
            d_19 = dm[(i0+1)+nao*(k0+9)];
            d_20 = dm[(i0+2)+nao*(k0+0)];
            d_21 = dm[(i0+2)+nao*(k0+1)];
            d_22 = dm[(i0+2)+nao*(k0+2)];
            d_23 = dm[(i0+2)+nao*(k0+3)];
            d_24 = dm[(i0+2)+nao*(k0+4)];
            d_25 = dm[(i0+2)+nao*(k0+5)];
            d_26 = dm[(i0+2)+nao*(k0+6)];
            d_27 = dm[(i0+2)+nao*(k0+7)];
            d_28 = dm[(i0+2)+nao*(k0+8)];
            d_29 = dm[(i0+2)+nao*(k0+9)];
            atomicAdd(vk+(j0+0)+nao*(l0+0), gout90*d_0+gout91*d_1+gout92*d_2+gout93*d_3+gout94*d_4+gout95*d_5+gout96*d_6+gout97*d_7+gout98*d_8+gout99*d_9+gout100*d_10+gout101*d_11+gout102*d_12+gout103*d_13+gout104*d_14+gout105*d_15+gout106*d_16+gout107*d_17+gout108*d_18+gout109*d_19+gout110*d_20+gout111*d_21+gout112*d_22+gout113*d_23+gout114*d_24+gout115*d_25+gout116*d_26+gout117*d_27+gout118*d_28+gout119*d_29);
            atomicAdd(vk+(j0+0)+nao*(l0+0)+nao2, gout120*d_0+gout121*d_1+gout122*d_2+gout123*d_3+gout124*d_4+gout125*d_5+gout126*d_6+gout127*d_7+gout128*d_8+gout129*d_9+gout130*d_10+gout131*d_11+gout132*d_12+gout133*d_13+gout134*d_14+gout135*d_15+gout136*d_16+gout137*d_17+gout138*d_18+gout139*d_19+gout140*d_20+gout141*d_21+gout142*d_22+gout143*d_23+gout144*d_24+gout145*d_25+gout146*d_26+gout147*d_27+gout148*d_28+gout149*d_29);
            atomicAdd(vk+(j0+0)+nao*(l0+0)+2*nao2, gout150*d_0+gout151*d_1+gout152*d_2+gout153*d_3+gout154*d_4+gout155*d_5+gout156*d_6+gout157*d_7+gout158*d_8+gout159*d_9+gout160*d_10+gout161*d_11+gout162*d_12+gout163*d_13+gout164*d_14+gout165*d_15+gout166*d_16+gout167*d_17+gout168*d_18+gout169*d_19+gout170*d_20+gout171*d_21+gout172*d_22+gout173*d_23+gout174*d_24+gout175*d_25+gout176*d_26+gout177*d_27+gout178*d_28+gout179*d_29);
            // ijkl, il -> jk
            d_0 = dm[(i0+0)+nao*(l0+0)];
            d_1 = dm[(i0+1)+nao*(l0+0)];
            d_2 = dm[(i0+2)+nao*(l0+0)];
            atomicAdd(vk+(j0+0)+nao*(k0+0), gout90*d_0+gout100*d_1+gout110*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+1), gout91*d_0+gout101*d_1+gout111*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+2), gout92*d_0+gout102*d_1+gout112*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+3), gout93*d_0+gout103*d_1+gout113*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+4), gout94*d_0+gout104*d_1+gout114*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+5), gout95*d_0+gout105*d_1+gout115*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+6), gout96*d_0+gout106*d_1+gout116*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+7), gout97*d_0+gout107*d_1+gout117*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+8), gout98*d_0+gout108*d_1+gout118*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+9), gout99*d_0+gout109*d_1+gout119*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+0)+nao2, gout120*d_0+gout130*d_1+gout140*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+1)+nao2, gout121*d_0+gout131*d_1+gout141*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+2)+nao2, gout122*d_0+gout132*d_1+gout142*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+3)+nao2, gout123*d_0+gout133*d_1+gout143*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+4)+nao2, gout124*d_0+gout134*d_1+gout144*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+5)+nao2, gout125*d_0+gout135*d_1+gout145*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+6)+nao2, gout126*d_0+gout136*d_1+gout146*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+7)+nao2, gout127*d_0+gout137*d_1+gout147*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+8)+nao2, gout128*d_0+gout138*d_1+gout148*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+9)+nao2, gout129*d_0+gout139*d_1+gout149*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+0)+2*nao2, gout150*d_0+gout160*d_1+gout170*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+1)+2*nao2, gout151*d_0+gout161*d_1+gout171*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+2)+2*nao2, gout152*d_0+gout162*d_1+gout172*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+3)+2*nao2, gout153*d_0+gout163*d_1+gout173*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+4)+2*nao2, gout154*d_0+gout164*d_1+gout174*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+5)+2*nao2, gout155*d_0+gout165*d_1+gout175*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+6)+2*nao2, gout156*d_0+gout166*d_1+gout176*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+7)+2*nao2, gout157*d_0+gout167*d_1+gout177*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+8)+2*nao2, gout158*d_0+gout168*d_1+gout178*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+9)+2*nao2, gout159*d_0+gout169*d_1+gout179*d_2);
            vk += 3*nao2;
        }
        dm += nao2;
    }
}

__global__
static void GINTint2e_ip1_jk_kernel_1110(GINTEnvVars envs, JKMatrix jk,
                                    BasisProdOffsets offsets)
{
    int ntasks_ij = offsets.ntasks_ij;
    int ntasks_kl = offsets.ntasks_kl;
    int task_ij = blockIdx.x * blockDim.x + threadIdx.x;
    int task_kl = blockIdx.y * blockDim.y + threadIdx.y;
    if (task_ij >= ntasks_ij || task_kl >= ntasks_kl) {
        return;
    }
    int bas_ij = offsets.bas_ij + task_ij;
    int bas_kl = offsets.bas_kl + task_kl;
    double norm = envs.fac;
    double omega = envs.omega;
    int *bas_pair2bra = c_bpcache.bas_pair2bra;
    int *bas_pair2ket = c_bpcache.bas_pair2ket;
    int ish = bas_pair2bra[bas_ij];
    int jsh = bas_pair2ket[bas_ij];
    int ksh = bas_pair2bra[bas_kl];
    int lsh = bas_pair2ket[bas_kl];
    int nprim_ij = envs.nprim_ij;
    int nprim_kl = envs.nprim_kl;
    int prim_ij = offsets.primitive_ij + task_ij * nprim_ij;
    int prim_kl = offsets.primitive_kl + task_kl * nprim_kl;

    double* __restrict__ a12 = c_bpcache.a12;
    double* __restrict__ e12 = c_bpcache.e12;
    double* __restrict__ x12 = c_bpcache.x12;
    double* __restrict__ y12 = c_bpcache.y12;
    double* __restrict__ z12 = c_bpcache.z12;
    double * __restrict__ i_exponent = c_bpcache.a1;
    double * __restrict__ j_exponent = c_bpcache.a2;

    int ij, kl;
    int prim_ij0, prim_ij1, prim_kl0, prim_kl1;
    int nbas = c_bpcache.nbas;
    double* __restrict__ bas_x = c_bpcache.bas_coords;
    double* __restrict__ bas_y = bas_x + nbas;
    double* __restrict__ bas_z = bas_y + nbas;

    double gout0 = 0;
    double gout1 = 0;
    double gout2 = 0;
    double gout3 = 0;
    double gout4 = 0;
    double gout5 = 0;
    double gout6 = 0;
    double gout7 = 0;
    double gout8 = 0;
    double gout9 = 0;
    double gout10 = 0;
    double gout11 = 0;
    double gout12 = 0;
    double gout13 = 0;
    double gout14 = 0;
    double gout15 = 0;
    double gout16 = 0;
    double gout17 = 0;
    double gout18 = 0;
    double gout19 = 0;
    double gout20 = 0;
    double gout21 = 0;
    double gout22 = 0;
    double gout23 = 0;
    double gout24 = 0;
    double gout25 = 0;
    double gout26 = 0;
    double gout27 = 0;
    double gout28 = 0;
    double gout29 = 0;
    double gout30 = 0;
    double gout31 = 0;
    double gout32 = 0;
    double gout33 = 0;
    double gout34 = 0;
    double gout35 = 0;
    double gout36 = 0;
    double gout37 = 0;
    double gout38 = 0;
    double gout39 = 0;
    double gout40 = 0;
    double gout41 = 0;
    double gout42 = 0;
    double gout43 = 0;
    double gout44 = 0;
    double gout45 = 0;
    double gout46 = 0;
    double gout47 = 0;
    double gout48 = 0;
    double gout49 = 0;
    double gout50 = 0;
    double gout51 = 0;
    double gout52 = 0;
    double gout53 = 0;
    double gout54 = 0;
    double gout55 = 0;
    double gout56 = 0;
    double gout57 = 0;
    double gout58 = 0;
    double gout59 = 0;
    double gout60 = 0;
    double gout61 = 0;
    double gout62 = 0;
    double gout63 = 0;
    double gout64 = 0;
    double gout65 = 0;
    double gout66 = 0;
    double gout67 = 0;
    double gout68 = 0;
    double gout69 = 0;
    double gout70 = 0;
    double gout71 = 0;
    double gout72 = 0;
    double gout73 = 0;
    double gout74 = 0;
    double gout75 = 0;
    double gout76 = 0;
    double gout77 = 0;
    double gout78 = 0;
    double gout79 = 0;
    double gout80 = 0;
    double gout81 = 0;
    double gout82 = 0;
    double gout83 = 0;
    double gout84 = 0;
    double gout85 = 0;
    double gout86 = 0;
    double gout87 = 0;
    double gout88 = 0;
    double gout89 = 0;
    double gout90 = 0;
    double gout91 = 0;
    double gout92 = 0;
    double gout93 = 0;
    double gout94 = 0;
    double gout95 = 0;
    double gout96 = 0;
    double gout97 = 0;
    double gout98 = 0;
    double gout99 = 0;
    double gout100 = 0;
    double gout101 = 0;
    double gout102 = 0;
    double gout103 = 0;
    double gout104 = 0;
    double gout105 = 0;
    double gout106 = 0;
    double gout107 = 0;
    double gout108 = 0;
    double gout109 = 0;
    double gout110 = 0;
    double gout111 = 0;
    double gout112 = 0;
    double gout113 = 0;
    double gout114 = 0;
    double gout115 = 0;
    double gout116 = 0;
    double gout117 = 0;
    double gout118 = 0;
    double gout119 = 0;
    double gout120 = 0;
    double gout121 = 0;
    double gout122 = 0;
    double gout123 = 0;
    double gout124 = 0;
    double gout125 = 0;
    double gout126 = 0;
    double gout127 = 0;
    double gout128 = 0;
    double gout129 = 0;
    double gout130 = 0;
    double gout131 = 0;
    double gout132 = 0;
    double gout133 = 0;
    double gout134 = 0;
    double gout135 = 0;
    double gout136 = 0;
    double gout137 = 0;
    double gout138 = 0;
    double gout139 = 0;
    double gout140 = 0;
    double gout141 = 0;
    double gout142 = 0;
    double gout143 = 0;
    double gout144 = 0;
    double gout145 = 0;
    double gout146 = 0;
    double gout147 = 0;
    double gout148 = 0;
    double gout149 = 0;
    double gout150 = 0;
    double gout151 = 0;
    double gout152 = 0;
    double gout153 = 0;
    double gout154 = 0;
    double gout155 = 0;
    double gout156 = 0;
    double gout157 = 0;
    double gout158 = 0;
    double gout159 = 0;
    double gout160 = 0;
    double gout161 = 0;

    double xi = bas_x[ish];
    double yi = bas_y[ish];
    double zi = bas_z[ish];
    double ABx = xi - bas_x[jsh];
    double ABy = yi - bas_y[jsh];
    double ABz = zi - bas_z[jsh];
    double xk = bas_x[ksh];
    double yk = bas_y[ksh];
    double zk = bas_z[ksh];

    prim_ij0 = prim_ij;
    prim_ij1 = prim_ij + nprim_ij;
    prim_kl0 = prim_kl;
    prim_kl1 = prim_kl + nprim_kl;
    double rw[6];
    int irys;
    for (ij = prim_ij0; ij < prim_ij1; ++ij) {
        double alpha = i_exponent[ij];
        double beta = j_exponent[ij];
        double aij = a12[ij];
        double eij = e12[ij];
        double xij = x12[ij];
        double yij = y12[ij];
        double zij = z12[ij];
    for (kl = prim_kl0; kl < prim_kl1; ++kl) {
        double akl = a12[kl];
        double ekl = e12[kl];
        double xkl = x12[kl];
        double ykl = y12[kl];
        double zkl = z12[kl];
        double xijxkl = xij - xkl;
        double yijykl = yij - ykl;
        double zijzkl = zij - zkl;
        double aijkl = aij + akl;
        double a1 = aij * akl;
        double a0 = a1 / aijkl;
        double theta = omega > 0.0 ? omega * omega / (omega * omega + a0) : 1.0; 
        a0 *= theta;
        double x = a0 * (xijxkl * xijxkl + yijykl * yijykl + zijzkl * zijzkl);
        double fac = norm * eij * ekl * sqrt(a0 / (a1 * a1 * a1));
        //double fac = norm * eij * ekl / (sqrt(aijkl) * a1);

        GINTrys_root<3>(x, rw);
        GINTscale_u<3>(rw, theta);
      for (irys = 0; irys < 3; ++irys) {
            double weight0 = rw[irys+3] * fac;
            double root0 = rw[irys];
            double u2 = a0 * root0;
            double tmp4 = .5 / (u2 * aijkl + a1);
            double B00 = u2 * tmp4;
            double tmp1 = 2 * B00;
            double B10 = B00 + tmp4 * akl;
            double tmp2 = tmp1 * akl;
            double C00x = xij - xi - tmp2 * xijxkl;
            double C00y = yij - yi - tmp2 * yijykl;
            double C00z = zij - zi - tmp2 * zijzkl;

            double tmp3 = tmp1 * aij;
            double D00x = xkl - xk + tmp3 * xijxkl;
            double D00y = ykl - yk + tmp3 * yijykl;
            double D00z = zkl - zk + tmp3 * zijzkl;

            double g0 = B10+C00x*C00x;
            double g1 = C00x*D00x;
            double g2 = B00+g1;
            double g3 = 2*B00*C00x;
            double g4 = g0*D00x;
            double g5 = g3+g4;
            double g6 = ABx+C00x;
            double g7 = C00x*g6;
            double g8 = B10+g7;
            double g9 = 3*B10*C00x;
            double g10 = ABx*g0;
            double g11 = g9+C00x*C00x*C00x+g10;
            double g12 = g6*D00x;
            double g13 = B00+g12;
            double g18 = (B00*(ABx+(2*C00x)))+(g8*D00x);
            double g19 = 3*B10;
            double g27 = (B00*(g19+(C00x*((2*ABx)+(3*C00x)))))+(g11*D00x);
            double g28 = B10+g6*g6;
            double g31 = (ABx*ABx*C00x)+g9+C00x*C00x*C00x+(2*ABx*g0);
            double g34 = (2*B00*g6)+(g28*D00x);
            double g41 = (4*ABx*B00*C00x)+(3*B00*g0)+(2*ABx*g0*D00x)+(C00x*(g19+C00x*C00x)*D00x)+(ABx*ABx*g2);
            double g42 = B10+C00y*C00y;
            double g44 = B00+(C00y*D00y);
            double g47 = (2*B00*C00y)+(g42*D00y);
            double g48 = ABy+C00y;
            double g50 = B10+(C00y*g48);
            double g51 = 3*B10*C00y;
            double g53 = g51+C00y*C00y*C00y+(ABy*g42);
            double g55 = B00+(g48*D00y);
            double g60 = (B00*(ABy+(2*C00y)))+(g50*D00y);
            double g68 = (B00*(g19+(C00y*((2*ABy)+(3*C00y)))))+(g53*D00y);
            double g69 = B10+g48*g48;
            double g72 = (ABy*ABy*C00y)+g51+C00y*C00y*C00y+(2*ABy*g42);
            double g75 = (2*B00*g48)+(g69*D00y);
            double g82 = (4*ABy*B00*C00y)+(3*B00*g42)+(2*ABy*g42*D00y)+(C00y*(g19+C00y*C00y)*D00y)+(ABy*ABy*g44);
            double g83 = B10+C00z*C00z;
            double g85 = B00+(C00z*D00z);
            double g88 = (2*B00*C00z)+(g83*D00z);
            double g89 = ABz+C00z;
            double g91 = B10+(C00z*g89);
            double g92 = 3*B10*C00z;
            double g94 = g92+C00z*C00z*C00z+(ABz*g83);
            double g96 = B00+(g89*D00z);
            double g101 = (B00*(ABz+(2*C00z)))+(g91*D00z);
            double g109 = (B00*(g19+(C00z*((2*ABz)+(3*C00z)))))+(g94*D00z);
            double g110 = B10+g89*g89;
            double g113 = (ABz*ABz*C00z)+g92+C00z*C00z*C00z+(2*ABz*g83);
            double g116 = (2*B00*g89)+(g110*D00z);
            double g123 = (4*ABz*B00*C00z)+(3*B00*g83)+(2*ABz*g83*D00z)+(C00z*(g19+C00z*C00z)*D00z)+(ABz*ABz*g85);

            gout0 += (-g13 + 2*alpha*g27) * weight0;
            gout1 += (-g6 + 2*alpha*g11) * (D00y) * weight0;
            gout2 += (-g6 + 2*alpha*g11) * (D00z) * weight0;
            gout3 += (-D00x + 2*alpha*g5) * (g48) * weight0;
            gout4 += (-1 + 2*alpha*g0) * (g55) * weight0;
            gout5 += (-1 + 2*alpha*g0) * (g48) * (D00z) * weight0;
            gout6 += (-D00x + 2*alpha*g5) * (g89) * weight0;
            gout7 += (-1 + 2*alpha*g0) * (D00y) * (g89) * weight0;
            gout8 += (-1 + 2*alpha*g0) * (g96) * weight0;
            gout9 += (2*alpha*g18) * (C00y) * weight0;
            gout10 += (2*alpha*g8) * (g44) * weight0;
            gout11 += (2*alpha*g8) * (C00y) * (D00z) * weight0;
            gout12 += (2*alpha*g2) * (g50) * weight0;
            gout13 += (2*alpha*C00x) * (g60) * weight0;
            gout14 += (2*alpha*C00x) * (g50) * (D00z) * weight0;
            gout15 += (2*alpha*g2) * (C00y) * (g89) * weight0;
            gout16 += (2*alpha*C00x) * (g44) * (g89) * weight0;
            gout17 += (2*alpha*C00x) * (C00y) * (g96) * weight0;
            gout18 += (2*alpha*g18) * (C00z) * weight0;
            gout19 += (2*alpha*g8) * (D00y) * (C00z) * weight0;
            gout20 += (2*alpha*g8) * (g85) * weight0;
            gout21 += (2*alpha*g2) * (g48) * (C00z) * weight0;
            gout22 += (2*alpha*C00x) * (g55) * (C00z) * weight0;
            gout23 += (2*alpha*C00x) * (g48) * (g85) * weight0;
            gout24 += (2*alpha*g2) * (g91) * weight0;
            gout25 += (2*alpha*C00x) * (D00y) * (g91) * weight0;
            gout26 += (2*alpha*C00x) * (g101) * weight0;
            gout27 += (g18) * (2*alpha*C00y) * weight0;
            gout28 += (g8) * (2*alpha*g44) * weight0;
            gout29 += (g8) * (2*alpha*C00y) * (D00z) * weight0;
            gout30 += (g2) * (2*alpha*g50) * weight0;
            gout31 += (C00x) * (2*alpha*g60) * weight0;
            gout32 += (C00x) * (2*alpha*g50) * (D00z) * weight0;
            gout33 += (g2) * (2*alpha*C00y) * (g89) * weight0;
            gout34 += (C00x) * (2*alpha*g44) * (g89) * weight0;
            gout35 += (C00x) * (2*alpha*C00y) * (g96) * weight0;
            gout36 += (g13) * (-1 + 2*alpha*g42) * weight0;
            gout37 += (g6) * (-D00y + 2*alpha*g47) * weight0;
            gout38 += (g6) * (-1 + 2*alpha*g42) * (D00z) * weight0;
            gout39 += (D00x) * (-g48 + 2*alpha*g53) * weight0;
            gout40 += (-g55 + 2*alpha*g68) * weight0;
            gout41 += (-g48 + 2*alpha*g53) * (D00z) * weight0;
            gout42 += (D00x) * (-1 + 2*alpha*g42) * (g89) * weight0;
            gout43 += (-D00y + 2*alpha*g47) * (g89) * weight0;
            gout44 += (-1 + 2*alpha*g42) * (g96) * weight0;
            gout45 += (g13) * (2*alpha*C00y) * (C00z) * weight0;
            gout46 += (g6) * (2*alpha*g44) * (C00z) * weight0;
            gout47 += (g6) * (2*alpha*C00y) * (g85) * weight0;
            gout48 += (D00x) * (2*alpha*g50) * (C00z) * weight0;
            gout49 += (2*alpha*g60) * (C00z) * weight0;
            gout50 += (2*alpha*g50) * (g85) * weight0;
            gout51 += (D00x) * (2*alpha*C00y) * (g91) * weight0;
            gout52 += (2*alpha*g44) * (g91) * weight0;
            gout53 += (2*alpha*C00y) * (g101) * weight0;
            gout54 += (g18) * (2*alpha*C00z) * weight0;
            gout55 += (g8) * (D00y) * (2*alpha*C00z) * weight0;
            gout56 += (g8) * (2*alpha*g85) * weight0;
            gout57 += (g2) * (g48) * (2*alpha*C00z) * weight0;
            gout58 += (C00x) * (g55) * (2*alpha*C00z) * weight0;
            gout59 += (C00x) * (g48) * (2*alpha*g85) * weight0;
            gout60 += (g2) * (2*alpha*g91) * weight0;
            gout61 += (C00x) * (D00y) * (2*alpha*g91) * weight0;
            gout62 += (C00x) * (2*alpha*g101) * weight0;
            gout63 += (g13) * (C00y) * (2*alpha*C00z) * weight0;
            gout64 += (g6) * (g44) * (2*alpha*C00z) * weight0;
            gout65 += (g6) * (C00y) * (2*alpha*g85) * weight0;
            gout66 += (D00x) * (g50) * (2*alpha*C00z) * weight0;
            gout67 += (g60) * (2*alpha*C00z) * weight0;
            gout68 += (g50) * (2*alpha*g85) * weight0;
            gout69 += (D00x) * (C00y) * (2*alpha*g91) * weight0;
            gout70 += (g44) * (2*alpha*g91) * weight0;
            gout71 += (C00y) * (2*alpha*g101) * weight0;
            gout72 += (g13) * (-1 + 2*alpha*g83) * weight0;
            gout73 += (g6) * (D00y) * (-1 + 2*alpha*g83) * weight0;
            gout74 += (g6) * (-D00z + 2*alpha*g88) * weight0;
            gout75 += (D00x) * (g48) * (-1 + 2*alpha*g83) * weight0;
            gout76 += (g55) * (-1 + 2*alpha*g83) * weight0;
            gout77 += (g48) * (-D00z + 2*alpha*g88) * weight0;
            gout78 += (D00x) * (-g89 + 2*alpha*g94) * weight0;
            gout79 += (D00y) * (-g89 + 2*alpha*g94) * weight0;
            gout80 += (-g96 + 2*alpha*g109) * weight0;
            gout81 += (-g2 + 2*beta*g41) * weight0;
            gout82 += (-C00x + 2*beta*g31) * (D00y) * weight0;
            gout83 += (-C00x + 2*beta*g31) * (D00z) * weight0;
            gout84 += (2*beta*g18) * (g48) * weight0;
            gout85 += (2*beta*g8) * (g55) * weight0;
            gout86 += (2*beta*g8) * (g48) * (D00z) * weight0;
            gout87 += (2*beta*g18) * (g89) * weight0;
            gout88 += (2*beta*g8) * (D00y) * (g89) * weight0;
            gout89 += (2*beta*g8) * (g96) * weight0;
            gout90 += (-D00x + 2*beta*g34) * (C00y) * weight0;
            gout91 += (-1 + 2*beta*g28) * (g44) * weight0;
            gout92 += (-1 + 2*beta*g28) * (C00y) * (D00z) * weight0;
            gout93 += (2*beta*g13) * (g50) * weight0;
            gout94 += (2*beta*g6) * (g60) * weight0;
            gout95 += (2*beta*g6) * (g50) * (D00z) * weight0;
            gout96 += (2*beta*g13) * (C00y) * (g89) * weight0;
            gout97 += (2*beta*g6) * (g44) * (g89) * weight0;
            gout98 += (2*beta*g6) * (C00y) * (g96) * weight0;
            gout99 += (-D00x + 2*beta*g34) * (C00z) * weight0;
            gout100 += (-1 + 2*beta*g28) * (D00y) * (C00z) * weight0;
            gout101 += (-1 + 2*beta*g28) * (g85) * weight0;
            gout102 += (2*beta*g13) * (g48) * (C00z) * weight0;
            gout103 += (2*beta*g6) * (g55) * (C00z) * weight0;
            gout104 += (2*beta*g6) * (g48) * (g85) * weight0;
            gout105 += (2*beta*g13) * (g91) * weight0;
            gout106 += (2*beta*g6) * (D00y) * (g91) * weight0;
            gout107 += (2*beta*g6) * (g101) * weight0;
            gout108 += (g18) * (2*beta*g48) * weight0;
            gout109 += (g8) * (2*beta*g55) * weight0;
            gout110 += (g8) * (2*beta*g48) * (D00z) * weight0;
            gout111 += (g2) * (-1 + 2*beta*g69) * weight0;
            gout112 += (C00x) * (-D00y + 2*beta*g75) * weight0;
            gout113 += (C00x) * (-1 + 2*beta*g69) * (D00z) * weight0;
            gout114 += (g2) * (2*beta*g48) * (g89) * weight0;
            gout115 += (C00x) * (2*beta*g55) * (g89) * weight0;
            gout116 += (C00x) * (2*beta*g48) * (g96) * weight0;
            gout117 += (g13) * (2*beta*g50) * weight0;
            gout118 += (g6) * (2*beta*g60) * weight0;
            gout119 += (g6) * (2*beta*g50) * (D00z) * weight0;
            gout120 += (D00x) * (-C00y + 2*beta*g72) * weight0;
            gout121 += (-g44 + 2*beta*g82) * weight0;
            gout122 += (-C00y + 2*beta*g72) * (D00z) * weight0;
            gout123 += (D00x) * (2*beta*g50) * (g89) * weight0;
            gout124 += (2*beta*g60) * (g89) * weight0;
            gout125 += (2*beta*g50) * (g96) * weight0;
            gout126 += (g13) * (2*beta*g48) * (C00z) * weight0;
            gout127 += (g6) * (2*beta*g55) * (C00z) * weight0;
            gout128 += (g6) * (2*beta*g48) * (g85) * weight0;
            gout129 += (D00x) * (-1 + 2*beta*g69) * (C00z) * weight0;
            gout130 += (-D00y + 2*beta*g75) * (C00z) * weight0;
            gout131 += (-1 + 2*beta*g69) * (g85) * weight0;
            gout132 += (D00x) * (2*beta*g48) * (g91) * weight0;
            gout133 += (2*beta*g55) * (g91) * weight0;
            gout134 += (2*beta*g48) * (g101) * weight0;
            gout135 += (g18) * (2*beta*g89) * weight0;
            gout136 += (g8) * (D00y) * (2*beta*g89) * weight0;
            gout137 += (g8) * (2*beta*g96) * weight0;
            gout138 += (g2) * (g48) * (2*beta*g89) * weight0;
            gout139 += (C00x) * (g55) * (2*beta*g89) * weight0;
            gout140 += (C00x) * (g48) * (2*beta*g96) * weight0;
            gout141 += (g2) * (-1 + 2*beta*g110) * weight0;
            gout142 += (C00x) * (D00y) * (-1 + 2*beta*g110) * weight0;
            gout143 += (C00x) * (-D00z + 2*beta*g116) * weight0;
            gout144 += (g13) * (C00y) * (2*beta*g89) * weight0;
            gout145 += (g6) * (g44) * (2*beta*g89) * weight0;
            gout146 += (g6) * (C00y) * (2*beta*g96) * weight0;
            gout147 += (D00x) * (g50) * (2*beta*g89) * weight0;
            gout148 += (g60) * (2*beta*g89) * weight0;
            gout149 += (g50) * (2*beta*g96) * weight0;
            gout150 += (D00x) * (C00y) * (-1 + 2*beta*g110) * weight0;
            gout151 += (g44) * (-1 + 2*beta*g110) * weight0;
            gout152 += (C00y) * (-D00z + 2*beta*g116) * weight0;
            gout153 += (g13) * (2*beta*g91) * weight0;
            gout154 += (g6) * (D00y) * (2*beta*g91) * weight0;
            gout155 += (g6) * (2*beta*g101) * weight0;
            gout156 += (D00x) * (g48) * (2*beta*g91) * weight0;
            gout157 += (g55) * (2*beta*g91) * weight0;
            gout158 += (g48) * (2*beta*g101) * weight0;
            gout159 += (D00x) * (-C00z + 2*beta*g113) * weight0;
            gout160 += (D00y) * (-C00z + 2*beta*g113) * weight0;
            gout161 += (-g85 + 2*beta*g123) * weight0;
        }
    } }

    int *ao_loc = c_bpcache.ao_loc;
    int i0 = ao_loc[ish];
    int j0 = ao_loc[jsh];
    int k0 = ao_loc[ksh];
    int l0 = ao_loc[lsh];
    int n_dm = jk.n_dm;
    int nao = jk.nao;
    size_t nao2 = nao * nao;
    double* __restrict__ dm = jk.dm;
    double *vj = jk.vj;
    double *vk = jk.vk;
    double d_0, d_1, d_2, d_3, d_4, d_5, d_6, d_7, d_8;

    for (int i_dm = 0; i_dm < n_dm; ++i_dm) {
        if (vj != NULL) {
            d_0 = dm[(k0+0)+nao*(l0+0)];
            d_1 = dm[(k0+1)+nao*(l0+0)];
            d_2 = dm[(k0+2)+nao*(l0+0)];
            atomicAdd(vj+(i0+0)+nao*(j0+0), gout0*d_0+gout1*d_1+gout2*d_2);
            atomicAdd(vj+(i0+0)+nao*(j0+1), gout3*d_0+gout4*d_1+gout5*d_2);
            atomicAdd(vj+(i0+0)+nao*(j0+2), gout6*d_0+gout7*d_1+gout8*d_2);
            atomicAdd(vj+(i0+1)+nao*(j0+0), gout9*d_0+gout10*d_1+gout11*d_2);
            atomicAdd(vj+(i0+1)+nao*(j0+1), gout12*d_0+gout13*d_1+gout14*d_2);
            atomicAdd(vj+(i0+1)+nao*(j0+2), gout15*d_0+gout16*d_1+gout17*d_2);
            atomicAdd(vj+(i0+2)+nao*(j0+0), gout18*d_0+gout19*d_1+gout20*d_2);
            atomicAdd(vj+(i0+2)+nao*(j0+1), gout21*d_0+gout22*d_1+gout23*d_2);
            atomicAdd(vj+(i0+2)+nao*(j0+2), gout24*d_0+gout25*d_1+gout26*d_2);
            atomicAdd(vj+(i0+0)+nao*(j0+0)+nao2, gout27*d_0+gout28*d_1+gout29*d_2);
            atomicAdd(vj+(i0+0)+nao*(j0+1)+nao2, gout30*d_0+gout31*d_1+gout32*d_2);
            atomicAdd(vj+(i0+0)+nao*(j0+2)+nao2, gout33*d_0+gout34*d_1+gout35*d_2);
            atomicAdd(vj+(i0+1)+nao*(j0+0)+nao2, gout36*d_0+gout37*d_1+gout38*d_2);
            atomicAdd(vj+(i0+1)+nao*(j0+1)+nao2, gout39*d_0+gout40*d_1+gout41*d_2);
            atomicAdd(vj+(i0+1)+nao*(j0+2)+nao2, gout42*d_0+gout43*d_1+gout44*d_2);
            atomicAdd(vj+(i0+2)+nao*(j0+0)+nao2, gout45*d_0+gout46*d_1+gout47*d_2);
            atomicAdd(vj+(i0+2)+nao*(j0+1)+nao2, gout48*d_0+gout49*d_1+gout50*d_2);
            atomicAdd(vj+(i0+2)+nao*(j0+2)+nao2, gout51*d_0+gout52*d_1+gout53*d_2);
            atomicAdd(vj+(i0+0)+nao*(j0+0)+2*nao2, gout54*d_0+gout55*d_1+gout56*d_2);
            atomicAdd(vj+(i0+0)+nao*(j0+1)+2*nao2, gout57*d_0+gout58*d_1+gout59*d_2);
            atomicAdd(vj+(i0+0)+nao*(j0+2)+2*nao2, gout60*d_0+gout61*d_1+gout62*d_2);
            atomicAdd(vj+(i0+1)+nao*(j0+0)+2*nao2, gout63*d_0+gout64*d_1+gout65*d_2);
            atomicAdd(vj+(i0+1)+nao*(j0+1)+2*nao2, gout66*d_0+gout67*d_1+gout68*d_2);
            atomicAdd(vj+(i0+1)+nao*(j0+2)+2*nao2, gout69*d_0+gout70*d_1+gout71*d_2);
            atomicAdd(vj+(i0+2)+nao*(j0+0)+2*nao2, gout72*d_0+gout73*d_1+gout74*d_2);
            atomicAdd(vj+(i0+2)+nao*(j0+1)+2*nao2, gout75*d_0+gout76*d_1+gout77*d_2);
            atomicAdd(vj+(i0+2)+nao*(j0+2)+2*nao2, gout78*d_0+gout79*d_1+gout80*d_2);
            atomicAdd(vj+nao*(i0+0)+(j0+0), gout81*d_0+gout82*d_1+gout83*d_2);
            atomicAdd(vj+nao*(i0+0)+(j0+1), gout84*d_0+gout85*d_1+gout86*d_2);
            atomicAdd(vj+nao*(i0+0)+(j0+2), gout87*d_0+gout88*d_1+gout89*d_2);
            atomicAdd(vj+nao*(i0+1)+(j0+0), gout90*d_0+gout91*d_1+gout92*d_2);
            atomicAdd(vj+nao*(i0+1)+(j0+1), gout93*d_0+gout94*d_1+gout95*d_2);
            atomicAdd(vj+nao*(i0+1)+(j0+2), gout96*d_0+gout97*d_1+gout98*d_2);
            atomicAdd(vj+nao*(i0+2)+(j0+0), gout99*d_0+gout100*d_1+gout101*d_2);
            atomicAdd(vj+nao*(i0+2)+(j0+1), gout102*d_0+gout103*d_1+gout104*d_2);
            atomicAdd(vj+nao*(i0+2)+(j0+2), gout105*d_0+gout106*d_1+gout107*d_2);
            atomicAdd(vj+nao*(i0+0)+(j0+0)+nao2, gout108*d_0+gout109*d_1+gout110*d_2);
            atomicAdd(vj+nao*(i0+0)+(j0+1)+nao2, gout111*d_0+gout112*d_1+gout113*d_2);
            atomicAdd(vj+nao*(i0+0)+(j0+2)+nao2, gout114*d_0+gout115*d_1+gout116*d_2);
            atomicAdd(vj+nao*(i0+1)+(j0+0)+nao2, gout117*d_0+gout118*d_1+gout119*d_2);
            atomicAdd(vj+nao*(i0+1)+(j0+1)+nao2, gout120*d_0+gout121*d_1+gout122*d_2);
            atomicAdd(vj+nao*(i0+1)+(j0+2)+nao2, gout123*d_0+gout124*d_1+gout125*d_2);
            atomicAdd(vj+nao*(i0+2)+(j0+0)+nao2, gout126*d_0+gout127*d_1+gout128*d_2);
            atomicAdd(vj+nao*(i0+2)+(j0+1)+nao2, gout129*d_0+gout130*d_1+gout131*d_2);
            atomicAdd(vj+nao*(i0+2)+(j0+2)+nao2, gout132*d_0+gout133*d_1+gout134*d_2);
            atomicAdd(vj+nao*(i0+0)+(j0+0)+2*nao2, gout135*d_0+gout136*d_1+gout137*d_2);
            atomicAdd(vj+nao*(i0+0)+(j0+1)+2*nao2, gout138*d_0+gout139*d_1+gout140*d_2);
            atomicAdd(vj+nao*(i0+0)+(j0+2)+2*nao2, gout141*d_0+gout142*d_1+gout143*d_2);
            atomicAdd(vj+nao*(i0+1)+(j0+0)+2*nao2, gout144*d_0+gout145*d_1+gout146*d_2);
            atomicAdd(vj+nao*(i0+1)+(j0+1)+2*nao2, gout147*d_0+gout148*d_1+gout149*d_2);
            atomicAdd(vj+nao*(i0+1)+(j0+2)+2*nao2, gout150*d_0+gout151*d_1+gout152*d_2);
            atomicAdd(vj+nao*(i0+2)+(j0+0)+2*nao2, gout153*d_0+gout154*d_1+gout155*d_2);
            atomicAdd(vj+nao*(i0+2)+(j0+1)+2*nao2, gout156*d_0+gout157*d_1+gout158*d_2);
            atomicAdd(vj+nao*(i0+2)+(j0+2)+2*nao2, gout159*d_0+gout160*d_1+gout161*d_2);
            vj += 3*nao2;
        }
        if (vk != NULL) {
            // ijkl, jk -> il
            d_0 = dm[(j0+0)+nao*(k0+0)];
            d_1 = dm[(j0+0)+nao*(k0+1)];
            d_2 = dm[(j0+0)+nao*(k0+2)];
            d_3 = dm[(j0+1)+nao*(k0+0)];
            d_4 = dm[(j0+1)+nao*(k0+1)];
            d_5 = dm[(j0+1)+nao*(k0+2)];
            d_6 = dm[(j0+2)+nao*(k0+0)];
            d_7 = dm[(j0+2)+nao*(k0+1)];
            d_8 = dm[(j0+2)+nao*(k0+2)];
            atomicAdd(vk+(i0+0)+nao*(l0+0), gout0*d_0+gout1*d_1+gout2*d_2+gout3*d_3+gout4*d_4+gout5*d_5+gout6*d_6+gout7*d_7+gout8*d_8);
            atomicAdd(vk+(i0+1)+nao*(l0+0), gout9*d_0+gout10*d_1+gout11*d_2+gout12*d_3+gout13*d_4+gout14*d_5+gout15*d_6+gout16*d_7+gout17*d_8);
            atomicAdd(vk+(i0+2)+nao*(l0+0), gout18*d_0+gout19*d_1+gout20*d_2+gout21*d_3+gout22*d_4+gout23*d_5+gout24*d_6+gout25*d_7+gout26*d_8);
            atomicAdd(vk+(i0+0)+nao*(l0+0)+nao2, gout27*d_0+gout28*d_1+gout29*d_2+gout30*d_3+gout31*d_4+gout32*d_5+gout33*d_6+gout34*d_7+gout35*d_8);
            atomicAdd(vk+(i0+1)+nao*(l0+0)+nao2, gout36*d_0+gout37*d_1+gout38*d_2+gout39*d_3+gout40*d_4+gout41*d_5+gout42*d_6+gout43*d_7+gout44*d_8);
            atomicAdd(vk+(i0+2)+nao*(l0+0)+nao2, gout45*d_0+gout46*d_1+gout47*d_2+gout48*d_3+gout49*d_4+gout50*d_5+gout51*d_6+gout52*d_7+gout53*d_8);
            atomicAdd(vk+(i0+0)+nao*(l0+0)+2*nao2, gout54*d_0+gout55*d_1+gout56*d_2+gout57*d_3+gout58*d_4+gout59*d_5+gout60*d_6+gout61*d_7+gout62*d_8);
            atomicAdd(vk+(i0+1)+nao*(l0+0)+2*nao2, gout63*d_0+gout64*d_1+gout65*d_2+gout66*d_3+gout67*d_4+gout68*d_5+gout69*d_6+gout70*d_7+gout71*d_8);
            atomicAdd(vk+(i0+2)+nao*(l0+0)+2*nao2, gout72*d_0+gout73*d_1+gout74*d_2+gout75*d_3+gout76*d_4+gout77*d_5+gout78*d_6+gout79*d_7+gout80*d_8);
            // ijkl, jl -> ik
            d_0 = dm[(j0+0)+nao*(l0+0)];
            d_1 = dm[(j0+1)+nao*(l0+0)];
            d_2 = dm[(j0+2)+nao*(l0+0)];
            atomicAdd(vk+(i0+0)+nao*(k0+0), gout0*d_0+gout3*d_1+gout6*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+1), gout1*d_0+gout4*d_1+gout7*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+2), gout2*d_0+gout5*d_1+gout8*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+0), gout9*d_0+gout12*d_1+gout15*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+1), gout10*d_0+gout13*d_1+gout16*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+2), gout11*d_0+gout14*d_1+gout17*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+0), gout18*d_0+gout21*d_1+gout24*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+1), gout19*d_0+gout22*d_1+gout25*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+2), gout20*d_0+gout23*d_1+gout26*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+0)+nao2, gout27*d_0+gout30*d_1+gout33*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+1)+nao2, gout28*d_0+gout31*d_1+gout34*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+2)+nao2, gout29*d_0+gout32*d_1+gout35*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+0)+nao2, gout36*d_0+gout39*d_1+gout42*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+1)+nao2, gout37*d_0+gout40*d_1+gout43*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+2)+nao2, gout38*d_0+gout41*d_1+gout44*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+0)+nao2, gout45*d_0+gout48*d_1+gout51*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+1)+nao2, gout46*d_0+gout49*d_1+gout52*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+2)+nao2, gout47*d_0+gout50*d_1+gout53*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+0)+2*nao2, gout54*d_0+gout57*d_1+gout60*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+1)+2*nao2, gout55*d_0+gout58*d_1+gout61*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+2)+2*nao2, gout56*d_0+gout59*d_1+gout62*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+0)+2*nao2, gout63*d_0+gout66*d_1+gout69*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+1)+2*nao2, gout64*d_0+gout67*d_1+gout70*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+2)+2*nao2, gout65*d_0+gout68*d_1+gout71*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+0)+2*nao2, gout72*d_0+gout75*d_1+gout78*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+1)+2*nao2, gout73*d_0+gout76*d_1+gout79*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+2)+2*nao2, gout74*d_0+gout77*d_1+gout80*d_2);
            // ijkl, ik -> jl
            d_0 = dm[(i0+0)+nao*(k0+0)];
            d_1 = dm[(i0+0)+nao*(k0+1)];
            d_2 = dm[(i0+0)+nao*(k0+2)];
            d_3 = dm[(i0+1)+nao*(k0+0)];
            d_4 = dm[(i0+1)+nao*(k0+1)];
            d_5 = dm[(i0+1)+nao*(k0+2)];
            d_6 = dm[(i0+2)+nao*(k0+0)];
            d_7 = dm[(i0+2)+nao*(k0+1)];
            d_8 = dm[(i0+2)+nao*(k0+2)];
            atomicAdd(vk+(j0+0)+nao*(l0+0), gout81*d_0+gout82*d_1+gout83*d_2+gout90*d_3+gout91*d_4+gout92*d_5+gout99*d_6+gout100*d_7+gout101*d_8);
            atomicAdd(vk+(j0+1)+nao*(l0+0), gout84*d_0+gout85*d_1+gout86*d_2+gout93*d_3+gout94*d_4+gout95*d_5+gout102*d_6+gout103*d_7+gout104*d_8);
            atomicAdd(vk+(j0+2)+nao*(l0+0), gout87*d_0+gout88*d_1+gout89*d_2+gout96*d_3+gout97*d_4+gout98*d_5+gout105*d_6+gout106*d_7+gout107*d_8);
            atomicAdd(vk+(j0+0)+nao*(l0+0)+nao2, gout108*d_0+gout109*d_1+gout110*d_2+gout117*d_3+gout118*d_4+gout119*d_5+gout126*d_6+gout127*d_7+gout128*d_8);
            atomicAdd(vk+(j0+1)+nao*(l0+0)+nao2, gout111*d_0+gout112*d_1+gout113*d_2+gout120*d_3+gout121*d_4+gout122*d_5+gout129*d_6+gout130*d_7+gout131*d_8);
            atomicAdd(vk+(j0+2)+nao*(l0+0)+nao2, gout114*d_0+gout115*d_1+gout116*d_2+gout123*d_3+gout124*d_4+gout125*d_5+gout132*d_6+gout133*d_7+gout134*d_8);
            atomicAdd(vk+(j0+0)+nao*(l0+0)+2*nao2, gout135*d_0+gout136*d_1+gout137*d_2+gout144*d_3+gout145*d_4+gout146*d_5+gout153*d_6+gout154*d_7+gout155*d_8);
            atomicAdd(vk+(j0+1)+nao*(l0+0)+2*nao2, gout138*d_0+gout139*d_1+gout140*d_2+gout147*d_3+gout148*d_4+gout149*d_5+gout156*d_6+gout157*d_7+gout158*d_8);
            atomicAdd(vk+(j0+2)+nao*(l0+0)+2*nao2, gout141*d_0+gout142*d_1+gout143*d_2+gout150*d_3+gout151*d_4+gout152*d_5+gout159*d_6+gout160*d_7+gout161*d_8);
            // ijkl, il -> jk
            d_0 = dm[(i0+0)+nao*(l0+0)];
            d_1 = dm[(i0+1)+nao*(l0+0)];
            d_2 = dm[(i0+2)+nao*(l0+0)];
            atomicAdd(vk+(j0+0)+nao*(k0+0), gout81*d_0+gout90*d_1+gout99*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+1), gout82*d_0+gout91*d_1+gout100*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+2), gout83*d_0+gout92*d_1+gout101*d_2);
            atomicAdd(vk+(j0+1)+nao*(k0+0), gout84*d_0+gout93*d_1+gout102*d_2);
            atomicAdd(vk+(j0+1)+nao*(k0+1), gout85*d_0+gout94*d_1+gout103*d_2);
            atomicAdd(vk+(j0+1)+nao*(k0+2), gout86*d_0+gout95*d_1+gout104*d_2);
            atomicAdd(vk+(j0+2)+nao*(k0+0), gout87*d_0+gout96*d_1+gout105*d_2);
            atomicAdd(vk+(j0+2)+nao*(k0+1), gout88*d_0+gout97*d_1+gout106*d_2);
            atomicAdd(vk+(j0+2)+nao*(k0+2), gout89*d_0+gout98*d_1+gout107*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+0)+nao2, gout108*d_0+gout117*d_1+gout126*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+1)+nao2, gout109*d_0+gout118*d_1+gout127*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+2)+nao2, gout110*d_0+gout119*d_1+gout128*d_2);
            atomicAdd(vk+(j0+1)+nao*(k0+0)+nao2, gout111*d_0+gout120*d_1+gout129*d_2);
            atomicAdd(vk+(j0+1)+nao*(k0+1)+nao2, gout112*d_0+gout121*d_1+gout130*d_2);
            atomicAdd(vk+(j0+1)+nao*(k0+2)+nao2, gout113*d_0+gout122*d_1+gout131*d_2);
            atomicAdd(vk+(j0+2)+nao*(k0+0)+nao2, gout114*d_0+gout123*d_1+gout132*d_2);
            atomicAdd(vk+(j0+2)+nao*(k0+1)+nao2, gout115*d_0+gout124*d_1+gout133*d_2);
            atomicAdd(vk+(j0+2)+nao*(k0+2)+nao2, gout116*d_0+gout125*d_1+gout134*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+0)+2*nao2, gout135*d_0+gout144*d_1+gout153*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+1)+2*nao2, gout136*d_0+gout145*d_1+gout154*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+2)+2*nao2, gout137*d_0+gout146*d_1+gout155*d_2);
            atomicAdd(vk+(j0+1)+nao*(k0+0)+2*nao2, gout138*d_0+gout147*d_1+gout156*d_2);
            atomicAdd(vk+(j0+1)+nao*(k0+1)+2*nao2, gout139*d_0+gout148*d_1+gout157*d_2);
            atomicAdd(vk+(j0+1)+nao*(k0+2)+2*nao2, gout140*d_0+gout149*d_1+gout158*d_2);
            atomicAdd(vk+(j0+2)+nao*(k0+0)+2*nao2, gout141*d_0+gout150*d_1+gout159*d_2);
            atomicAdd(vk+(j0+2)+nao*(k0+1)+2*nao2, gout142*d_0+gout151*d_1+gout160*d_2);
            atomicAdd(vk+(j0+2)+nao*(k0+2)+2*nao2, gout143*d_0+gout152*d_1+gout161*d_2);
            vk += 3*nao2;
        }
        dm += nao2;
    }
}

__global__
static void GINTint2e_ip1_jk_kernel_1111(GINTEnvVars envs, JKMatrix jk,
                                    BasisProdOffsets offsets)
{
    int ntasks_ij = offsets.ntasks_ij;
    int ntasks_kl = offsets.ntasks_kl;
    int task_ij = blockIdx.x * blockDim.x + threadIdx.x;
    int task_kl = blockIdx.y * blockDim.y + threadIdx.y;
    if (task_ij >= ntasks_ij || task_kl >= ntasks_kl) {
        return;
    }
    int bas_ij = offsets.bas_ij + task_ij;
    int bas_kl = offsets.bas_kl + task_kl;
    double norm = envs.fac;
    double omega = envs.omega;
    int *bas_pair2bra = c_bpcache.bas_pair2bra;
    int *bas_pair2ket = c_bpcache.bas_pair2ket;
    int ish = bas_pair2bra[bas_ij];
    int jsh = bas_pair2ket[bas_ij];
    int ksh = bas_pair2bra[bas_kl];
    int lsh = bas_pair2ket[bas_kl];
    int nprim_ij = envs.nprim_ij;
    int nprim_kl = envs.nprim_kl;
    int prim_ij = offsets.primitive_ij + task_ij * nprim_ij;
    int prim_kl = offsets.primitive_kl + task_kl * nprim_kl;

    double* __restrict__ a12 = c_bpcache.a12;
    double* __restrict__ e12 = c_bpcache.e12;
    double* __restrict__ x12 = c_bpcache.x12;
    double* __restrict__ y12 = c_bpcache.y12;
    double* __restrict__ z12 = c_bpcache.z12;
    double * __restrict__ i_exponent = c_bpcache.a1;
    double * __restrict__ j_exponent = c_bpcache.a2;

    int ij, kl;
    int prim_ij0, prim_ij1, prim_kl0, prim_kl1;
    int nbas = c_bpcache.nbas;
    double* __restrict__ bas_x = c_bpcache.bas_coords;
    double* __restrict__ bas_y = bas_x + nbas;
    double* __restrict__ bas_z = bas_y + nbas;

    double gout0 = 0;
    double gout1 = 0;
    double gout2 = 0;
    double gout3 = 0;
    double gout4 = 0;
    double gout5 = 0;
    double gout6 = 0;
    double gout7 = 0;
    double gout8 = 0;
    double gout9 = 0;
    double gout10 = 0;
    double gout11 = 0;
    double gout12 = 0;
    double gout13 = 0;
    double gout14 = 0;
    double gout15 = 0;
    double gout16 = 0;
    double gout17 = 0;
    double gout18 = 0;
    double gout19 = 0;
    double gout20 = 0;
    double gout21 = 0;
    double gout22 = 0;
    double gout23 = 0;
    double gout24 = 0;
    double gout25 = 0;
    double gout26 = 0;
    double gout27 = 0;
    double gout28 = 0;
    double gout29 = 0;
    double gout30 = 0;
    double gout31 = 0;
    double gout32 = 0;
    double gout33 = 0;
    double gout34 = 0;
    double gout35 = 0;
    double gout36 = 0;
    double gout37 = 0;
    double gout38 = 0;
    double gout39 = 0;
    double gout40 = 0;
    double gout41 = 0;
    double gout42 = 0;
    double gout43 = 0;
    double gout44 = 0;
    double gout45 = 0;
    double gout46 = 0;
    double gout47 = 0;
    double gout48 = 0;
    double gout49 = 0;
    double gout50 = 0;
    double gout51 = 0;
    double gout52 = 0;
    double gout53 = 0;
    double gout54 = 0;
    double gout55 = 0;
    double gout56 = 0;
    double gout57 = 0;
    double gout58 = 0;
    double gout59 = 0;
    double gout60 = 0;
    double gout61 = 0;
    double gout62 = 0;
    double gout63 = 0;
    double gout64 = 0;
    double gout65 = 0;
    double gout66 = 0;
    double gout67 = 0;
    double gout68 = 0;
    double gout69 = 0;
    double gout70 = 0;
    double gout71 = 0;
    double gout72 = 0;
    double gout73 = 0;
    double gout74 = 0;
    double gout75 = 0;
    double gout76 = 0;
    double gout77 = 0;
    double gout78 = 0;
    double gout79 = 0;
    double gout80 = 0;
    double gout81 = 0;
    double gout82 = 0;
    double gout83 = 0;
    double gout84 = 0;
    double gout85 = 0;
    double gout86 = 0;
    double gout87 = 0;
    double gout88 = 0;
    double gout89 = 0;
    double gout90 = 0;
    double gout91 = 0;
    double gout92 = 0;
    double gout93 = 0;
    double gout94 = 0;
    double gout95 = 0;
    double gout96 = 0;
    double gout97 = 0;
    double gout98 = 0;
    double gout99 = 0;
    double gout100 = 0;
    double gout101 = 0;
    double gout102 = 0;
    double gout103 = 0;
    double gout104 = 0;
    double gout105 = 0;
    double gout106 = 0;
    double gout107 = 0;
    double gout108 = 0;
    double gout109 = 0;
    double gout110 = 0;
    double gout111 = 0;
    double gout112 = 0;
    double gout113 = 0;
    double gout114 = 0;
    double gout115 = 0;
    double gout116 = 0;
    double gout117 = 0;
    double gout118 = 0;
    double gout119 = 0;
    double gout120 = 0;
    double gout121 = 0;
    double gout122 = 0;
    double gout123 = 0;
    double gout124 = 0;
    double gout125 = 0;
    double gout126 = 0;
    double gout127 = 0;
    double gout128 = 0;
    double gout129 = 0;
    double gout130 = 0;
    double gout131 = 0;
    double gout132 = 0;
    double gout133 = 0;
    double gout134 = 0;
    double gout135 = 0;
    double gout136 = 0;
    double gout137 = 0;
    double gout138 = 0;
    double gout139 = 0;
    double gout140 = 0;
    double gout141 = 0;
    double gout142 = 0;
    double gout143 = 0;
    double gout144 = 0;
    double gout145 = 0;
    double gout146 = 0;
    double gout147 = 0;
    double gout148 = 0;
    double gout149 = 0;
    double gout150 = 0;
    double gout151 = 0;
    double gout152 = 0;
    double gout153 = 0;
    double gout154 = 0;
    double gout155 = 0;
    double gout156 = 0;
    double gout157 = 0;
    double gout158 = 0;
    double gout159 = 0;
    double gout160 = 0;
    double gout161 = 0;
    double gout162 = 0;
    double gout163 = 0;
    double gout164 = 0;
    double gout165 = 0;
    double gout166 = 0;
    double gout167 = 0;
    double gout168 = 0;
    double gout169 = 0;
    double gout170 = 0;
    double gout171 = 0;
    double gout172 = 0;
    double gout173 = 0;
    double gout174 = 0;
    double gout175 = 0;
    double gout176 = 0;
    double gout177 = 0;
    double gout178 = 0;
    double gout179 = 0;
    double gout180 = 0;
    double gout181 = 0;
    double gout182 = 0;
    double gout183 = 0;
    double gout184 = 0;
    double gout185 = 0;
    double gout186 = 0;
    double gout187 = 0;
    double gout188 = 0;
    double gout189 = 0;
    double gout190 = 0;
    double gout191 = 0;
    double gout192 = 0;
    double gout193 = 0;
    double gout194 = 0;
    double gout195 = 0;
    double gout196 = 0;
    double gout197 = 0;
    double gout198 = 0;
    double gout199 = 0;
    double gout200 = 0;
    double gout201 = 0;
    double gout202 = 0;
    double gout203 = 0;
    double gout204 = 0;
    double gout205 = 0;
    double gout206 = 0;
    double gout207 = 0;
    double gout208 = 0;
    double gout209 = 0;
    double gout210 = 0;
    double gout211 = 0;
    double gout212 = 0;
    double gout213 = 0;
    double gout214 = 0;
    double gout215 = 0;
    double gout216 = 0;
    double gout217 = 0;
    double gout218 = 0;
    double gout219 = 0;
    double gout220 = 0;
    double gout221 = 0;
    double gout222 = 0;
    double gout223 = 0;
    double gout224 = 0;
    double gout225 = 0;
    double gout226 = 0;
    double gout227 = 0;
    double gout228 = 0;
    double gout229 = 0;
    double gout230 = 0;
    double gout231 = 0;
    double gout232 = 0;
    double gout233 = 0;
    double gout234 = 0;
    double gout235 = 0;
    double gout236 = 0;
    double gout237 = 0;
    double gout238 = 0;
    double gout239 = 0;
    double gout240 = 0;
    double gout241 = 0;
    double gout242 = 0;
    double gout243 = 0;
    double gout244 = 0;
    double gout245 = 0;
    double gout246 = 0;
    double gout247 = 0;
    double gout248 = 0;
    double gout249 = 0;
    double gout250 = 0;
    double gout251 = 0;
    double gout252 = 0;
    double gout253 = 0;
    double gout254 = 0;
    double gout255 = 0;
    double gout256 = 0;
    double gout257 = 0;
    double gout258 = 0;
    double gout259 = 0;
    double gout260 = 0;
    double gout261 = 0;
    double gout262 = 0;
    double gout263 = 0;
    double gout264 = 0;
    double gout265 = 0;
    double gout266 = 0;
    double gout267 = 0;
    double gout268 = 0;
    double gout269 = 0;
    double gout270 = 0;
    double gout271 = 0;
    double gout272 = 0;
    double gout273 = 0;
    double gout274 = 0;
    double gout275 = 0;
    double gout276 = 0;
    double gout277 = 0;
    double gout278 = 0;
    double gout279 = 0;
    double gout280 = 0;
    double gout281 = 0;
    double gout282 = 0;
    double gout283 = 0;
    double gout284 = 0;
    double gout285 = 0;
    double gout286 = 0;
    double gout287 = 0;
    double gout288 = 0;
    double gout289 = 0;
    double gout290 = 0;
    double gout291 = 0;
    double gout292 = 0;
    double gout293 = 0;
    double gout294 = 0;
    double gout295 = 0;
    double gout296 = 0;
    double gout297 = 0;
    double gout298 = 0;
    double gout299 = 0;
    double gout300 = 0;
    double gout301 = 0;
    double gout302 = 0;
    double gout303 = 0;
    double gout304 = 0;
    double gout305 = 0;
    double gout306 = 0;
    double gout307 = 0;
    double gout308 = 0;
    double gout309 = 0;
    double gout310 = 0;
    double gout311 = 0;
    double gout312 = 0;
    double gout313 = 0;
    double gout314 = 0;
    double gout315 = 0;
    double gout316 = 0;
    double gout317 = 0;
    double gout318 = 0;
    double gout319 = 0;
    double gout320 = 0;
    double gout321 = 0;
    double gout322 = 0;
    double gout323 = 0;
    double gout324 = 0;
    double gout325 = 0;
    double gout326 = 0;
    double gout327 = 0;
    double gout328 = 0;
    double gout329 = 0;
    double gout330 = 0;
    double gout331 = 0;
    double gout332 = 0;
    double gout333 = 0;
    double gout334 = 0;
    double gout335 = 0;
    double gout336 = 0;
    double gout337 = 0;
    double gout338 = 0;
    double gout339 = 0;
    double gout340 = 0;
    double gout341 = 0;
    double gout342 = 0;
    double gout343 = 0;
    double gout344 = 0;
    double gout345 = 0;
    double gout346 = 0;
    double gout347 = 0;
    double gout348 = 0;
    double gout349 = 0;
    double gout350 = 0;
    double gout351 = 0;
    double gout352 = 0;
    double gout353 = 0;
    double gout354 = 0;
    double gout355 = 0;
    double gout356 = 0;
    double gout357 = 0;
    double gout358 = 0;
    double gout359 = 0;
    double gout360 = 0;
    double gout361 = 0;
    double gout362 = 0;
    double gout363 = 0;
    double gout364 = 0;
    double gout365 = 0;
    double gout366 = 0;
    double gout367 = 0;
    double gout368 = 0;
    double gout369 = 0;
    double gout370 = 0;
    double gout371 = 0;
    double gout372 = 0;
    double gout373 = 0;
    double gout374 = 0;
    double gout375 = 0;
    double gout376 = 0;
    double gout377 = 0;
    double gout378 = 0;
    double gout379 = 0;
    double gout380 = 0;
    double gout381 = 0;
    double gout382 = 0;
    double gout383 = 0;
    double gout384 = 0;
    double gout385 = 0;
    double gout386 = 0;
    double gout387 = 0;
    double gout388 = 0;
    double gout389 = 0;
    double gout390 = 0;
    double gout391 = 0;
    double gout392 = 0;
    double gout393 = 0;
    double gout394 = 0;
    double gout395 = 0;
    double gout396 = 0;
    double gout397 = 0;
    double gout398 = 0;
    double gout399 = 0;
    double gout400 = 0;
    double gout401 = 0;
    double gout402 = 0;
    double gout403 = 0;
    double gout404 = 0;
    double gout405 = 0;
    double gout406 = 0;
    double gout407 = 0;
    double gout408 = 0;
    double gout409 = 0;
    double gout410 = 0;
    double gout411 = 0;
    double gout412 = 0;
    double gout413 = 0;
    double gout414 = 0;
    double gout415 = 0;
    double gout416 = 0;
    double gout417 = 0;
    double gout418 = 0;
    double gout419 = 0;
    double gout420 = 0;
    double gout421 = 0;
    double gout422 = 0;
    double gout423 = 0;
    double gout424 = 0;
    double gout425 = 0;
    double gout426 = 0;
    double gout427 = 0;
    double gout428 = 0;
    double gout429 = 0;
    double gout430 = 0;
    double gout431 = 0;
    double gout432 = 0;
    double gout433 = 0;
    double gout434 = 0;
    double gout435 = 0;
    double gout436 = 0;
    double gout437 = 0;
    double gout438 = 0;
    double gout439 = 0;
    double gout440 = 0;
    double gout441 = 0;
    double gout442 = 0;
    double gout443 = 0;
    double gout444 = 0;
    double gout445 = 0;
    double gout446 = 0;
    double gout447 = 0;
    double gout448 = 0;
    double gout449 = 0;
    double gout450 = 0;
    double gout451 = 0;
    double gout452 = 0;
    double gout453 = 0;
    double gout454 = 0;
    double gout455 = 0;
    double gout456 = 0;
    double gout457 = 0;
    double gout458 = 0;
    double gout459 = 0;
    double gout460 = 0;
    double gout461 = 0;
    double gout462 = 0;
    double gout463 = 0;
    double gout464 = 0;
    double gout465 = 0;
    double gout466 = 0;
    double gout467 = 0;
    double gout468 = 0;
    double gout469 = 0;
    double gout470 = 0;
    double gout471 = 0;
    double gout472 = 0;
    double gout473 = 0;
    double gout474 = 0;
    double gout475 = 0;
    double gout476 = 0;
    double gout477 = 0;
    double gout478 = 0;
    double gout479 = 0;
    double gout480 = 0;
    double gout481 = 0;
    double gout482 = 0;
    double gout483 = 0;
    double gout484 = 0;
    double gout485 = 0;

    double xi = bas_x[ish];
    double yi = bas_y[ish];
    double zi = bas_z[ish];
    double ABx = xi - bas_x[jsh];
    double ABy = yi - bas_y[jsh];
    double ABz = zi - bas_z[jsh];
    double xk = bas_x[ksh];
    double yk = bas_y[ksh];
    double zk = bas_z[ksh];
    double CDx = xk - bas_x[lsh];
    double CDy = yk - bas_y[lsh];
    double CDz = zk - bas_z[lsh];
    prim_ij0 = prim_ij;
    prim_ij1 = prim_ij + nprim_ij;
    prim_kl0 = prim_kl;
    prim_kl1 = prim_kl + nprim_kl;
    double rw[6];
    int irys;
    for (ij = prim_ij0; ij < prim_ij1; ++ij) {
        double alpha = i_exponent[ij];
        double beta = j_exponent[ij];
        double aij = a12[ij];
        double eij = e12[ij];
        double xij = x12[ij];
        double yij = y12[ij];
        double zij = z12[ij];
    for (kl = prim_kl0; kl < prim_kl1; ++kl) {
        double akl = a12[kl];
        double ekl = e12[kl];
        double xkl = x12[kl];
        double ykl = y12[kl];
        double zkl = z12[kl];
        double xijxkl = xij - xkl;
        double yijykl = yij - ykl;
        double zijzkl = zij - zkl;
        double aijkl = aij + akl;
        double a1 = aij * akl;
        double a0 = a1 / aijkl;
        double theta = omega > 0.0 ? omega * omega / (omega * omega + a0) : 1.0; 
        a0 *= theta;
        double x = a0 * (xijxkl * xijxkl + yijykl * yijykl + zijzkl * zijzkl);
        double fac = norm * eij * ekl * sqrt(a0 / (a1 * a1 * a1));
        //double fac = norm * eij * ekl / (sqrt(aijkl) * a1);

        GINTrys_root<3>(x, rw);
        GINTscale_u<3>(rw, theta);
      for (irys = 0; irys < 3; ++irys) {
            double weight0 = rw[irys+3] * fac;
            double root0 = rw[irys];
            double u2 = a0 * root0;
            double tmp4 = .5 / (u2 * aijkl + a1);
            double B00 = u2 * tmp4;
            double tmp1 = 2 * B00;
            double B10 = B00 + tmp4 * akl;
            double tmp2 = tmp1 * akl;
            double C00x = xij - xi - tmp2 * xijxkl;
            double C00y = yij - yi - tmp2 * yijykl;
            double C00z = zij - zi - tmp2 * zijzkl;
            double B01 = B00 + tmp4 * aij;
            double tmp3 = tmp1 * aij;
            double D00x = xkl - xk + tmp3 * xijxkl;
            double D00y = ykl - yk + tmp3 * yijykl;
            double D00z = zkl - zk + tmp3 * zijzkl;

            double g0 = B10+C00x*C00x;
            double g1 = C00x*D00x;
            double g2 = B00+g1;
            double g3 = 2*B00*C00x;
            double g4 = g0*D00x;
            double g5 = g3+g4;
            double g6 = ABx+C00x;
            double g7 = C00x*g6;
            double g8 = B10+g7;
            double g9 = 3*B10*C00x;
            double g10 = ABx*g0;
            double g11 = g9+C00x*C00x*C00x+g10;
            double g12 = g6*D00x;
            double g13 = B00+g12;
            double g14 = 2*C00x;
            double g15 = ABx+g14;
            double g16 = B00*g15;
            double g17 = g8*D00x;
            double g18 = g16+g17;
            double g19 = 3*B10;
            double g20 = 2*ABx;
            double g21 = 3*C00x;
            double g22 = g20+g21;
            double g23 = C00x*g22;
            double g24 = g19+g23;
            double g25 = B00*g24;
            double g26 = g11*D00x;
            double g27 = g25+g26;
            double g28 = B10+g6*g6;
            double g31 = (ABx*ABx*C00x)+g9+C00x*C00x*C00x+(2*ABx*g0);
            double g34 = (2*B00*g6)+(g28*D00x);
            double g36 = 3*B00*g0;
            double g38 = g19+C00x*C00x;
            double g41 = (4*ABx*B00*C00x)+g36+(2*ABx*g0*D00x)+(C00x*g38*D00x)+(ABx*ABx*g2);
            double g42 = CDx+D00x;
            double g44 = B00+(C00x*g42);
            double g45 = g0*g42;
            double g46 = g3+g45;
            double g48 = B01+(D00x*g42);
            double g52 = CDx+(2*D00x);
            double g53 = B00*g52;
            double g54 = (B01*C00x)+(C00x*D00x*g42)+g53;
            double g55 = 2*B00*B00;
            double g58 = g55+(2*B00*C00x*g52)+(g0*g48);
            double g60 = B00+(g6*g42);
            double g62 = g3+g45+(ABx*g44);
            double g64 = g25+(g11*g42);
            double g66 = g53+(g6*g48);
            double g69 = g55+(B00*g15*g52)+(g8*g48);
            double g70 = 6*B00*B00*C00x;
            double g71 = 3*B00*g0*g52;
            double g72 = C00x*g38*g48;
            double g74 = g70+g71+g72+(ABx*g58);
            double g77 = g3+(ABx*ABx*g42)+g45+(2*ABx*g44);
            double g81 = g36+(C00x*g38*g42)+(ABx*ABx*g44)+(2*ABx*g46);
            double g84 = g55+(2*B00*g6*g52)+(g28*g48);
            double g89 = g70+g71+g72+(ABx*ABx*(g53+(C00x*g48)))+(2*ABx*g58);
            double g90 = B10+C00y*C00y;
            double g92 = B00+(C00y*D00y);
            double g93 = 2*B00*C00y;
            double g95 = g93+(g90*D00y);
            double g96 = ABy+C00y;
            double g98 = B10+(C00y*g96);
            double g99 = 3*B10*C00y;
            double g101 = g99+C00y*C00y*C00y+(ABy*g90);
            double g103 = B00+(g96*D00y);
            double g105 = ABy+(2*C00y);
            double g108 = (B00*g105)+(g98*D00y);
            double g114 = B00*(g19+(C00y*((2*ABy)+(3*C00y))));
            double g116 = g114+(g101*D00y);
            double g117 = B10+g96*g96;
            double g120 = (ABy*ABy*C00y)+g99+C00y*C00y*C00y+(2*ABy*g90);
            double g123 = (2*B00*g96)+(g117*D00y);
            double g125 = 3*B00*g90;
            double g127 = g19+C00y*C00y;
            double g130 = (4*ABy*B00*C00y)+g125+(2*ABy*g90*D00y)+(C00y*g127*D00y)+(ABy*ABy*g92);
            double g131 = CDy+D00y;
            double g133 = B00+(C00y*g131);
            double g134 = g90*g131;
            double g135 = g93+g134;
            double g137 = B01+(D00y*g131);
            double g141 = CDy+(2*D00y);
            double g142 = B00*g141;
            double g143 = (B01*C00y)+(C00y*D00y*g131)+g142;
            double g146 = g55+(2*B00*C00y*g141)+(g90*g137);
            double g148 = B00+(g96*g131);
            double g150 = g93+g134+(ABy*g133);
            double g152 = g114+(g101*g131);
            double g154 = g142+(g96*g137);
            double g157 = g55+(B00*g105*g141)+(g98*g137);
            double g158 = 6*B00*B00*C00y;
            double g159 = 3*B00*g90*g141;
            double g160 = C00y*g127*g137;
            double g162 = g158+g159+g160+(ABy*g146);
            double g165 = g93+(ABy*ABy*g131)+g134+(2*ABy*g133);
            double g169 = g125+(C00y*g127*g131)+(ABy*ABy*g133)+(2*ABy*g135);
            double g172 = g55+(2*B00*g96*g141)+(g117*g137);
            double g177 = g158+g159+g160+(ABy*ABy*(g142+(C00y*g137)))+(2*ABy*g146);
            double g178 = B10+C00z*C00z;
            double g180 = B00+(C00z*D00z);
            double g181 = 2*B00*C00z;
            double g183 = g181+(g178*D00z);
            double g184 = ABz+C00z;
            double g186 = B10+(C00z*g184);
            double g187 = 3*B10*C00z;
            double g189 = g187+C00z*C00z*C00z+(ABz*g178);
            double g191 = B00+(g184*D00z);
            double g193 = ABz+(2*C00z);
            double g196 = (B00*g193)+(g186*D00z);
            double g202 = B00*(g19+(C00z*((2*ABz)+(3*C00z))));
            double g204 = g202+(g189*D00z);
            double g205 = B10+g184*g184;
            double g208 = (ABz*ABz*C00z)+g187+C00z*C00z*C00z+(2*ABz*g178);
            double g211 = (2*B00*g184)+(g205*D00z);
            double g213 = 3*B00*g178;
            double g215 = g19+C00z*C00z;
            double g218 = (4*ABz*B00*C00z)+g213+(2*ABz*g178*D00z)+(C00z*g215*D00z)+(ABz*ABz*g180);
            double g219 = CDz+D00z;
            double g221 = B00+(C00z*g219);
            double g222 = g178*g219;
            double g223 = g181+g222;
            double g225 = B01+(D00z*g219);
            double g229 = CDz+(2*D00z);
            double g230 = B00*g229;
            double g231 = (B01*C00z)+(C00z*D00z*g219)+g230;
            double g234 = g55+(2*B00*C00z*g229)+(g178*g225);
            double g236 = B00+(g184*g219);
            double g238 = g181+g222+(ABz*g221);
            double g240 = g202+(g189*g219);
            double g242 = g230+(g184*g225);
            double g245 = g55+(B00*g193*g229)+(g186*g225);
            double g246 = 6*B00*B00*C00z;
            double g247 = 3*B00*g178*g229;
            double g248 = C00z*g215*g225;
            double g250 = g246+g247+g248+(ABz*g234);
            double g253 = g181+(ABz*ABz*g219)+g222+(2*ABz*g221);
            double g257 = g213+(C00z*g215*g219)+(ABz*ABz*g221)+(2*ABz*g223);
            double g260 = g55+(2*B00*g184*g229)+(g205*g225);
            double g265 = g246+g247+g248+(ABz*ABz*(g230+(C00z*g225)))+(2*ABz*g234);

            gout0 += (-g66 + 2*alpha*g74) * weight0;
            gout1 += (-g13 + 2*alpha*g27) * (g131) * weight0;
            gout2 += (-g13 + 2*alpha*g27) * (g219) * weight0;
            gout3 += (-g60 + 2*alpha*g64) * (D00y) * weight0;
            gout4 += (-g6 + 2*alpha*g11) * (g137) * weight0;
            gout5 += (-g6 + 2*alpha*g11) * (D00y) * (g219) * weight0;
            gout6 += (-g60 + 2*alpha*g64) * (D00z) * weight0;
            gout7 += (-g6 + 2*alpha*g11) * (g131) * (D00z) * weight0;
            gout8 += (-g6 + 2*alpha*g11) * (g225) * weight0;
            gout9 += (-g48 + 2*alpha*g58) * (g96) * weight0;
            gout10 += (-D00x + 2*alpha*g5) * (g148) * weight0;
            gout11 += (-D00x + 2*alpha*g5) * (g96) * (g219) * weight0;
            gout12 += (-g42 + 2*alpha*g46) * (g103) * weight0;
            gout13 += (-1 + 2*alpha*g0) * (g154) * weight0;
            gout14 += (-1 + 2*alpha*g0) * (g103) * (g219) * weight0;
            gout15 += (-g42 + 2*alpha*g46) * (g96) * (D00z) * weight0;
            gout16 += (-1 + 2*alpha*g0) * (g148) * (D00z) * weight0;
            gout17 += (-1 + 2*alpha*g0) * (g96) * (g225) * weight0;
            gout18 += (-g48 + 2*alpha*g58) * (g184) * weight0;
            gout19 += (-D00x + 2*alpha*g5) * (g131) * (g184) * weight0;
            gout20 += (-D00x + 2*alpha*g5) * (g236) * weight0;
            gout21 += (-g42 + 2*alpha*g46) * (D00y) * (g184) * weight0;
            gout22 += (-1 + 2*alpha*g0) * (g137) * (g184) * weight0;
            gout23 += (-1 + 2*alpha*g0) * (D00y) * (g236) * weight0;
            gout24 += (-g42 + 2*alpha*g46) * (g191) * weight0;
            gout25 += (-1 + 2*alpha*g0) * (g131) * (g191) * weight0;
            gout26 += (-1 + 2*alpha*g0) * (g242) * weight0;
            gout27 += (2*alpha*g69) * (C00y) * weight0;
            gout28 += (2*alpha*g18) * (g133) * weight0;
            gout29 += (2*alpha*g18) * (C00y) * (g219) * weight0;
            gout30 += (2*alpha*g62) * (g92) * weight0;
            gout31 += (2*alpha*g8) * (g143) * weight0;
            gout32 += (2*alpha*g8) * (g92) * (g219) * weight0;
            gout33 += (2*alpha*g62) * (C00y) * (D00z) * weight0;
            gout34 += (2*alpha*g8) * (g133) * (D00z) * weight0;
            gout35 += (2*alpha*g8) * (C00y) * (g225) * weight0;
            gout36 += (2*alpha*g54) * (g98) * weight0;
            gout37 += (2*alpha*g2) * (g150) * weight0;
            gout38 += (2*alpha*g2) * (g98) * (g219) * weight0;
            gout39 += (2*alpha*g44) * (g108) * weight0;
            gout40 += (2*alpha*C00x) * (g157) * weight0;
            gout41 += (2*alpha*C00x) * (g108) * (g219) * weight0;
            gout42 += (2*alpha*g44) * (g98) * (D00z) * weight0;
            gout43 += (2*alpha*C00x) * (g150) * (D00z) * weight0;
            gout44 += (2*alpha*C00x) * (g98) * (g225) * weight0;
            gout45 += (2*alpha*g54) * (C00y) * (g184) * weight0;
            gout46 += (2*alpha*g2) * (g133) * (g184) * weight0;
            gout47 += (2*alpha*g2) * (C00y) * (g236) * weight0;
            gout48 += (2*alpha*g44) * (g92) * (g184) * weight0;
            gout49 += (2*alpha*C00x) * (g143) * (g184) * weight0;
            gout50 += (2*alpha*C00x) * (g92) * (g236) * weight0;
            gout51 += (2*alpha*g44) * (C00y) * (g191) * weight0;
            gout52 += (2*alpha*C00x) * (g133) * (g191) * weight0;
            gout53 += (2*alpha*C00x) * (C00y) * (g242) * weight0;
            gout54 += (2*alpha*g69) * (C00z) * weight0;
            gout55 += (2*alpha*g18) * (g131) * (C00z) * weight0;
            gout56 += (2*alpha*g18) * (g221) * weight0;
            gout57 += (2*alpha*g62) * (D00y) * (C00z) * weight0;
            gout58 += (2*alpha*g8) * (g137) * (C00z) * weight0;
            gout59 += (2*alpha*g8) * (D00y) * (g221) * weight0;
            gout60 += (2*alpha*g62) * (g180) * weight0;
            gout61 += (2*alpha*g8) * (g131) * (g180) * weight0;
            gout62 += (2*alpha*g8) * (g231) * weight0;
            gout63 += (2*alpha*g54) * (g96) * (C00z) * weight0;
            gout64 += (2*alpha*g2) * (g148) * (C00z) * weight0;
            gout65 += (2*alpha*g2) * (g96) * (g221) * weight0;
            gout66 += (2*alpha*g44) * (g103) * (C00z) * weight0;
            gout67 += (2*alpha*C00x) * (g154) * (C00z) * weight0;
            gout68 += (2*alpha*C00x) * (g103) * (g221) * weight0;
            gout69 += (2*alpha*g44) * (g96) * (g180) * weight0;
            gout70 += (2*alpha*C00x) * (g148) * (g180) * weight0;
            gout71 += (2*alpha*C00x) * (g96) * (g231) * weight0;
            gout72 += (2*alpha*g54) * (g186) * weight0;
            gout73 += (2*alpha*g2) * (g131) * (g186) * weight0;
            gout74 += (2*alpha*g2) * (g238) * weight0;
            gout75 += (2*alpha*g44) * (D00y) * (g186) * weight0;
            gout76 += (2*alpha*C00x) * (g137) * (g186) * weight0;
            gout77 += (2*alpha*C00x) * (D00y) * (g238) * weight0;
            gout78 += (2*alpha*g44) * (g196) * weight0;
            gout79 += (2*alpha*C00x) * (g131) * (g196) * weight0;
            gout80 += (2*alpha*C00x) * (g245) * weight0;
            gout81 += (g69) * (2*alpha*C00y) * weight0;
            gout82 += (g18) * (2*alpha*g133) * weight0;
            gout83 += (g18) * (2*alpha*C00y) * (g219) * weight0;
            gout84 += (g62) * (2*alpha*g92) * weight0;
            gout85 += (g8) * (2*alpha*g143) * weight0;
            gout86 += (g8) * (2*alpha*g92) * (g219) * weight0;
            gout87 += (g62) * (2*alpha*C00y) * (D00z) * weight0;
            gout88 += (g8) * (2*alpha*g133) * (D00z) * weight0;
            gout89 += (g8) * (2*alpha*C00y) * (g225) * weight0;
            gout90 += (g54) * (2*alpha*g98) * weight0;
            gout91 += (g2) * (2*alpha*g150) * weight0;
            gout92 += (g2) * (2*alpha*g98) * (g219) * weight0;
            gout93 += (g44) * (2*alpha*g108) * weight0;
            gout94 += (C00x) * (2*alpha*g157) * weight0;
            gout95 += (C00x) * (2*alpha*g108) * (g219) * weight0;
            gout96 += (g44) * (2*alpha*g98) * (D00z) * weight0;
            gout97 += (C00x) * (2*alpha*g150) * (D00z) * weight0;
            gout98 += (C00x) * (2*alpha*g98) * (g225) * weight0;
            gout99 += (g54) * (2*alpha*C00y) * (g184) * weight0;
            gout100 += (g2) * (2*alpha*g133) * (g184) * weight0;
            gout101 += (g2) * (2*alpha*C00y) * (g236) * weight0;
            gout102 += (g44) * (2*alpha*g92) * (g184) * weight0;
            gout103 += (C00x) * (2*alpha*g143) * (g184) * weight0;
            gout104 += (C00x) * (2*alpha*g92) * (g236) * weight0;
            gout105 += (g44) * (2*alpha*C00y) * (g191) * weight0;
            gout106 += (C00x) * (2*alpha*g133) * (g191) * weight0;
            gout107 += (C00x) * (2*alpha*C00y) * (g242) * weight0;
            gout108 += (g66) * (-1 + 2*alpha*g90) * weight0;
            gout109 += (g13) * (-g131 + 2*alpha*g135) * weight0;
            gout110 += (g13) * (-1 + 2*alpha*g90) * (g219) * weight0;
            gout111 += (g60) * (-D00y + 2*alpha*g95) * weight0;
            gout112 += (g6) * (-g137 + 2*alpha*g146) * weight0;
            gout113 += (g6) * (-D00y + 2*alpha*g95) * (g219) * weight0;
            gout114 += (g60) * (-1 + 2*alpha*g90) * (D00z) * weight0;
            gout115 += (g6) * (-g131 + 2*alpha*g135) * (D00z) * weight0;
            gout116 += (g6) * (-1 + 2*alpha*g90) * (g225) * weight0;
            gout117 += (g48) * (-g96 + 2*alpha*g101) * weight0;
            gout118 += (D00x) * (-g148 + 2*alpha*g152) * weight0;
            gout119 += (D00x) * (-g96 + 2*alpha*g101) * (g219) * weight0;
            gout120 += (g42) * (-g103 + 2*alpha*g116) * weight0;
            gout121 += (-g154 + 2*alpha*g162) * weight0;
            gout122 += (-g103 + 2*alpha*g116) * (g219) * weight0;
            gout123 += (g42) * (-g96 + 2*alpha*g101) * (D00z) * weight0;
            gout124 += (-g148 + 2*alpha*g152) * (D00z) * weight0;
            gout125 += (-g96 + 2*alpha*g101) * (g225) * weight0;
            gout126 += (g48) * (-1 + 2*alpha*g90) * (g184) * weight0;
            gout127 += (D00x) * (-g131 + 2*alpha*g135) * (g184) * weight0;
            gout128 += (D00x) * (-1 + 2*alpha*g90) * (g236) * weight0;
            gout129 += (g42) * (-D00y + 2*alpha*g95) * (g184) * weight0;
            gout130 += (-g137 + 2*alpha*g146) * (g184) * weight0;
            gout131 += (-D00y + 2*alpha*g95) * (g236) * weight0;
            gout132 += (g42) * (-1 + 2*alpha*g90) * (g191) * weight0;
            gout133 += (-g131 + 2*alpha*g135) * (g191) * weight0;
            gout134 += (-1 + 2*alpha*g90) * (g242) * weight0;
            gout135 += (g66) * (2*alpha*C00y) * (C00z) * weight0;
            gout136 += (g13) * (2*alpha*g133) * (C00z) * weight0;
            gout137 += (g13) * (2*alpha*C00y) * (g221) * weight0;
            gout138 += (g60) * (2*alpha*g92) * (C00z) * weight0;
            gout139 += (g6) * (2*alpha*g143) * (C00z) * weight0;
            gout140 += (g6) * (2*alpha*g92) * (g221) * weight0;
            gout141 += (g60) * (2*alpha*C00y) * (g180) * weight0;
            gout142 += (g6) * (2*alpha*g133) * (g180) * weight0;
            gout143 += (g6) * (2*alpha*C00y) * (g231) * weight0;
            gout144 += (g48) * (2*alpha*g98) * (C00z) * weight0;
            gout145 += (D00x) * (2*alpha*g150) * (C00z) * weight0;
            gout146 += (D00x) * (2*alpha*g98) * (g221) * weight0;
            gout147 += (g42) * (2*alpha*g108) * (C00z) * weight0;
            gout148 += (2*alpha*g157) * (C00z) * weight0;
            gout149 += (2*alpha*g108) * (g221) * weight0;
            gout150 += (g42) * (2*alpha*g98) * (g180) * weight0;
            gout151 += (2*alpha*g150) * (g180) * weight0;
            gout152 += (2*alpha*g98) * (g231) * weight0;
            gout153 += (g48) * (2*alpha*C00y) * (g186) * weight0;
            gout154 += (D00x) * (2*alpha*g133) * (g186) * weight0;
            gout155 += (D00x) * (2*alpha*C00y) * (g238) * weight0;
            gout156 += (g42) * (2*alpha*g92) * (g186) * weight0;
            gout157 += (2*alpha*g143) * (g186) * weight0;
            gout158 += (2*alpha*g92) * (g238) * weight0;
            gout159 += (g42) * (2*alpha*C00y) * (g196) * weight0;
            gout160 += (2*alpha*g133) * (g196) * weight0;
            gout161 += (2*alpha*C00y) * (g245) * weight0;
            gout162 += (g69) * (2*alpha*C00z) * weight0;
            gout163 += (g18) * (g131) * (2*alpha*C00z) * weight0;
            gout164 += (g18) * (2*alpha*g221) * weight0;
            gout165 += (g62) * (D00y) * (2*alpha*C00z) * weight0;
            gout166 += (g8) * (g137) * (2*alpha*C00z) * weight0;
            gout167 += (g8) * (D00y) * (2*alpha*g221) * weight0;
            gout168 += (g62) * (2*alpha*g180) * weight0;
            gout169 += (g8) * (g131) * (2*alpha*g180) * weight0;
            gout170 += (g8) * (2*alpha*g231) * weight0;
            gout171 += (g54) * (g96) * (2*alpha*C00z) * weight0;
            gout172 += (g2) * (g148) * (2*alpha*C00z) * weight0;
            gout173 += (g2) * (g96) * (2*alpha*g221) * weight0;
            gout174 += (g44) * (g103) * (2*alpha*C00z) * weight0;
            gout175 += (C00x) * (g154) * (2*alpha*C00z) * weight0;
            gout176 += (C00x) * (g103) * (2*alpha*g221) * weight0;
            gout177 += (g44) * (g96) * (2*alpha*g180) * weight0;
            gout178 += (C00x) * (g148) * (2*alpha*g180) * weight0;
            gout179 += (C00x) * (g96) * (2*alpha*g231) * weight0;
            gout180 += (g54) * (2*alpha*g186) * weight0;
            gout181 += (g2) * (g131) * (2*alpha*g186) * weight0;
            gout182 += (g2) * (2*alpha*g238) * weight0;
            gout183 += (g44) * (D00y) * (2*alpha*g186) * weight0;
            gout184 += (C00x) * (g137) * (2*alpha*g186) * weight0;
            gout185 += (C00x) * (D00y) * (2*alpha*g238) * weight0;
            gout186 += (g44) * (2*alpha*g196) * weight0;
            gout187 += (C00x) * (g131) * (2*alpha*g196) * weight0;
            gout188 += (C00x) * (2*alpha*g245) * weight0;
            gout189 += (g66) * (C00y) * (2*alpha*C00z) * weight0;
            gout190 += (g13) * (g133) * (2*alpha*C00z) * weight0;
            gout191 += (g13) * (C00y) * (2*alpha*g221) * weight0;
            gout192 += (g60) * (g92) * (2*alpha*C00z) * weight0;
            gout193 += (g6) * (g143) * (2*alpha*C00z) * weight0;
            gout194 += (g6) * (g92) * (2*alpha*g221) * weight0;
            gout195 += (g60) * (C00y) * (2*alpha*g180) * weight0;
            gout196 += (g6) * (g133) * (2*alpha*g180) * weight0;
            gout197 += (g6) * (C00y) * (2*alpha*g231) * weight0;
            gout198 += (g48) * (g98) * (2*alpha*C00z) * weight0;
            gout199 += (D00x) * (g150) * (2*alpha*C00z) * weight0;
            gout200 += (D00x) * (g98) * (2*alpha*g221) * weight0;
            gout201 += (g42) * (g108) * (2*alpha*C00z) * weight0;
            gout202 += (g157) * (2*alpha*C00z) * weight0;
            gout203 += (g108) * (2*alpha*g221) * weight0;
            gout204 += (g42) * (g98) * (2*alpha*g180) * weight0;
            gout205 += (g150) * (2*alpha*g180) * weight0;
            gout206 += (g98) * (2*alpha*g231) * weight0;
            gout207 += (g48) * (C00y) * (2*alpha*g186) * weight0;
            gout208 += (D00x) * (g133) * (2*alpha*g186) * weight0;
            gout209 += (D00x) * (C00y) * (2*alpha*g238) * weight0;
            gout210 += (g42) * (g92) * (2*alpha*g186) * weight0;
            gout211 += (g143) * (2*alpha*g186) * weight0;
            gout212 += (g92) * (2*alpha*g238) * weight0;
            gout213 += (g42) * (C00y) * (2*alpha*g196) * weight0;
            gout214 += (g133) * (2*alpha*g196) * weight0;
            gout215 += (C00y) * (2*alpha*g245) * weight0;
            gout216 += (g66) * (-1 + 2*alpha*g178) * weight0;
            gout217 += (g13) * (g131) * (-1 + 2*alpha*g178) * weight0;
            gout218 += (g13) * (-g219 + 2*alpha*g223) * weight0;
            gout219 += (g60) * (D00y) * (-1 + 2*alpha*g178) * weight0;
            gout220 += (g6) * (g137) * (-1 + 2*alpha*g178) * weight0;
            gout221 += (g6) * (D00y) * (-g219 + 2*alpha*g223) * weight0;
            gout222 += (g60) * (-D00z + 2*alpha*g183) * weight0;
            gout223 += (g6) * (g131) * (-D00z + 2*alpha*g183) * weight0;
            gout224 += (g6) * (-g225 + 2*alpha*g234) * weight0;
            gout225 += (g48) * (g96) * (-1 + 2*alpha*g178) * weight0;
            gout226 += (D00x) * (g148) * (-1 + 2*alpha*g178) * weight0;
            gout227 += (D00x) * (g96) * (-g219 + 2*alpha*g223) * weight0;
            gout228 += (g42) * (g103) * (-1 + 2*alpha*g178) * weight0;
            gout229 += (g154) * (-1 + 2*alpha*g178) * weight0;
            gout230 += (g103) * (-g219 + 2*alpha*g223) * weight0;
            gout231 += (g42) * (g96) * (-D00z + 2*alpha*g183) * weight0;
            gout232 += (g148) * (-D00z + 2*alpha*g183) * weight0;
            gout233 += (g96) * (-g225 + 2*alpha*g234) * weight0;
            gout234 += (g48) * (-g184 + 2*alpha*g189) * weight0;
            gout235 += (D00x) * (g131) * (-g184 + 2*alpha*g189) * weight0;
            gout236 += (D00x) * (-g236 + 2*alpha*g240) * weight0;
            gout237 += (g42) * (D00y) * (-g184 + 2*alpha*g189) * weight0;
            gout238 += (g137) * (-g184 + 2*alpha*g189) * weight0;
            gout239 += (D00y) * (-g236 + 2*alpha*g240) * weight0;
            gout240 += (g42) * (-g191 + 2*alpha*g204) * weight0;
            gout241 += (g131) * (-g191 + 2*alpha*g204) * weight0;
            gout242 += (-g242 + 2*alpha*g250) * weight0;
            gout243 += (-g54 + 2*beta*g89) * weight0;
            gout244 += (-g2 + 2*beta*g41) * (g131) * weight0;
            gout245 += (-g2 + 2*beta*g41) * (g219) * weight0;
            gout246 += (-g44 + 2*beta*g81) * (D00y) * weight0;
            gout247 += (-C00x + 2*beta*g31) * (g137) * weight0;
            gout248 += (-C00x + 2*beta*g31) * (D00y) * (g219) * weight0;
            gout249 += (-g44 + 2*beta*g81) * (D00z) * weight0;
            gout250 += (-C00x + 2*beta*g31) * (g131) * (D00z) * weight0;
            gout251 += (-C00x + 2*beta*g31) * (g225) * weight0;
            gout252 += (2*beta*g69) * (g96) * weight0;
            gout253 += (2*beta*g18) * (g148) * weight0;
            gout254 += (2*beta*g18) * (g96) * (g219) * weight0;
            gout255 += (2*beta*g62) * (g103) * weight0;
            gout256 += (2*beta*g8) * (g154) * weight0;
            gout257 += (2*beta*g8) * (g103) * (g219) * weight0;
            gout258 += (2*beta*g62) * (g96) * (D00z) * weight0;
            gout259 += (2*beta*g8) * (g148) * (D00z) * weight0;
            gout260 += (2*beta*g8) * (g96) * (g225) * weight0;
            gout261 += (2*beta*g69) * (g184) * weight0;
            gout262 += (2*beta*g18) * (g131) * (g184) * weight0;
            gout263 += (2*beta*g18) * (g236) * weight0;
            gout264 += (2*beta*g62) * (D00y) * (g184) * weight0;
            gout265 += (2*beta*g8) * (g137) * (g184) * weight0;
            gout266 += (2*beta*g8) * (D00y) * (g236) * weight0;
            gout267 += (2*beta*g62) * (g191) * weight0;
            gout268 += (2*beta*g8) * (g131) * (g191) * weight0;
            gout269 += (2*beta*g8) * (g242) * weight0;
            gout270 += (-g48 + 2*beta*g84) * (C00y) * weight0;
            gout271 += (-D00x + 2*beta*g34) * (g133) * weight0;
            gout272 += (-D00x + 2*beta*g34) * (C00y) * (g219) * weight0;
            gout273 += (-g42 + 2*beta*g77) * (g92) * weight0;
            gout274 += (-1 + 2*beta*g28) * (g143) * weight0;
            gout275 += (-1 + 2*beta*g28) * (g92) * (g219) * weight0;
            gout276 += (-g42 + 2*beta*g77) * (C00y) * (D00z) * weight0;
            gout277 += (-1 + 2*beta*g28) * (g133) * (D00z) * weight0;
            gout278 += (-1 + 2*beta*g28) * (C00y) * (g225) * weight0;
            gout279 += (2*beta*g66) * (g98) * weight0;
            gout280 += (2*beta*g13) * (g150) * weight0;
            gout281 += (2*beta*g13) * (g98) * (g219) * weight0;
            gout282 += (2*beta*g60) * (g108) * weight0;
            gout283 += (2*beta*g6) * (g157) * weight0;
            gout284 += (2*beta*g6) * (g108) * (g219) * weight0;
            gout285 += (2*beta*g60) * (g98) * (D00z) * weight0;
            gout286 += (2*beta*g6) * (g150) * (D00z) * weight0;
            gout287 += (2*beta*g6) * (g98) * (g225) * weight0;
            gout288 += (2*beta*g66) * (C00y) * (g184) * weight0;
            gout289 += (2*beta*g13) * (g133) * (g184) * weight0;
            gout290 += (2*beta*g13) * (C00y) * (g236) * weight0;
            gout291 += (2*beta*g60) * (g92) * (g184) * weight0;
            gout292 += (2*beta*g6) * (g143) * (g184) * weight0;
            gout293 += (2*beta*g6) * (g92) * (g236) * weight0;
            gout294 += (2*beta*g60) * (C00y) * (g191) * weight0;
            gout295 += (2*beta*g6) * (g133) * (g191) * weight0;
            gout296 += (2*beta*g6) * (C00y) * (g242) * weight0;
            gout297 += (-g48 + 2*beta*g84) * (C00z) * weight0;
            gout298 += (-D00x + 2*beta*g34) * (g131) * (C00z) * weight0;
            gout299 += (-D00x + 2*beta*g34) * (g221) * weight0;
            gout300 += (-g42 + 2*beta*g77) * (D00y) * (C00z) * weight0;
            gout301 += (-1 + 2*beta*g28) * (g137) * (C00z) * weight0;
            gout302 += (-1 + 2*beta*g28) * (D00y) * (g221) * weight0;
            gout303 += (-g42 + 2*beta*g77) * (g180) * weight0;
            gout304 += (-1 + 2*beta*g28) * (g131) * (g180) * weight0;
            gout305 += (-1 + 2*beta*g28) * (g231) * weight0;
            gout306 += (2*beta*g66) * (g96) * (C00z) * weight0;
            gout307 += (2*beta*g13) * (g148) * (C00z) * weight0;
            gout308 += (2*beta*g13) * (g96) * (g221) * weight0;
            gout309 += (2*beta*g60) * (g103) * (C00z) * weight0;
            gout310 += (2*beta*g6) * (g154) * (C00z) * weight0;
            gout311 += (2*beta*g6) * (g103) * (g221) * weight0;
            gout312 += (2*beta*g60) * (g96) * (g180) * weight0;
            gout313 += (2*beta*g6) * (g148) * (g180) * weight0;
            gout314 += (2*beta*g6) * (g96) * (g231) * weight0;
            gout315 += (2*beta*g66) * (g186) * weight0;
            gout316 += (2*beta*g13) * (g131) * (g186) * weight0;
            gout317 += (2*beta*g13) * (g238) * weight0;
            gout318 += (2*beta*g60) * (D00y) * (g186) * weight0;
            gout319 += (2*beta*g6) * (g137) * (g186) * weight0;
            gout320 += (2*beta*g6) * (D00y) * (g238) * weight0;
            gout321 += (2*beta*g60) * (g196) * weight0;
            gout322 += (2*beta*g6) * (g131) * (g196) * weight0;
            gout323 += (2*beta*g6) * (g245) * weight0;
            gout324 += (g69) * (2*beta*g96) * weight0;
            gout325 += (g18) * (2*beta*g148) * weight0;
            gout326 += (g18) * (2*beta*g96) * (g219) * weight0;
            gout327 += (g62) * (2*beta*g103) * weight0;
            gout328 += (g8) * (2*beta*g154) * weight0;
            gout329 += (g8) * (2*beta*g103) * (g219) * weight0;
            gout330 += (g62) * (2*beta*g96) * (D00z) * weight0;
            gout331 += (g8) * (2*beta*g148) * (D00z) * weight0;
            gout332 += (g8) * (2*beta*g96) * (g225) * weight0;
            gout333 += (g54) * (-1 + 2*beta*g117) * weight0;
            gout334 += (g2) * (-g131 + 2*beta*g165) * weight0;
            gout335 += (g2) * (-1 + 2*beta*g117) * (g219) * weight0;
            gout336 += (g44) * (-D00y + 2*beta*g123) * weight0;
            gout337 += (C00x) * (-g137 + 2*beta*g172) * weight0;
            gout338 += (C00x) * (-D00y + 2*beta*g123) * (g219) * weight0;
            gout339 += (g44) * (-1 + 2*beta*g117) * (D00z) * weight0;
            gout340 += (C00x) * (-g131 + 2*beta*g165) * (D00z) * weight0;
            gout341 += (C00x) * (-1 + 2*beta*g117) * (g225) * weight0;
            gout342 += (g54) * (2*beta*g96) * (g184) * weight0;
            gout343 += (g2) * (2*beta*g148) * (g184) * weight0;
            gout344 += (g2) * (2*beta*g96) * (g236) * weight0;
            gout345 += (g44) * (2*beta*g103) * (g184) * weight0;
            gout346 += (C00x) * (2*beta*g154) * (g184) * weight0;
            gout347 += (C00x) * (2*beta*g103) * (g236) * weight0;
            gout348 += (g44) * (2*beta*g96) * (g191) * weight0;
            gout349 += (C00x) * (2*beta*g148) * (g191) * weight0;
            gout350 += (C00x) * (2*beta*g96) * (g242) * weight0;
            gout351 += (g66) * (2*beta*g98) * weight0;
            gout352 += (g13) * (2*beta*g150) * weight0;
            gout353 += (g13) * (2*beta*g98) * (g219) * weight0;
            gout354 += (g60) * (2*beta*g108) * weight0;
            gout355 += (g6) * (2*beta*g157) * weight0;
            gout356 += (g6) * (2*beta*g108) * (g219) * weight0;
            gout357 += (g60) * (2*beta*g98) * (D00z) * weight0;
            gout358 += (g6) * (2*beta*g150) * (D00z) * weight0;
            gout359 += (g6) * (2*beta*g98) * (g225) * weight0;
            gout360 += (g48) * (-C00y + 2*beta*g120) * weight0;
            gout361 += (D00x) * (-g133 + 2*beta*g169) * weight0;
            gout362 += (D00x) * (-C00y + 2*beta*g120) * (g219) * weight0;
            gout363 += (g42) * (-g92 + 2*beta*g130) * weight0;
            gout364 += (-g143 + 2*beta*g177) * weight0;
            gout365 += (-g92 + 2*beta*g130) * (g219) * weight0;
            gout366 += (g42) * (-C00y + 2*beta*g120) * (D00z) * weight0;
            gout367 += (-g133 + 2*beta*g169) * (D00z) * weight0;
            gout368 += (-C00y + 2*beta*g120) * (g225) * weight0;
            gout369 += (g48) * (2*beta*g98) * (g184) * weight0;
            gout370 += (D00x) * (2*beta*g150) * (g184) * weight0;
            gout371 += (D00x) * (2*beta*g98) * (g236) * weight0;
            gout372 += (g42) * (2*beta*g108) * (g184) * weight0;
            gout373 += (2*beta*g157) * (g184) * weight0;
            gout374 += (2*beta*g108) * (g236) * weight0;
            gout375 += (g42) * (2*beta*g98) * (g191) * weight0;
            gout376 += (2*beta*g150) * (g191) * weight0;
            gout377 += (2*beta*g98) * (g242) * weight0;
            gout378 += (g66) * (2*beta*g96) * (C00z) * weight0;
            gout379 += (g13) * (2*beta*g148) * (C00z) * weight0;
            gout380 += (g13) * (2*beta*g96) * (g221) * weight0;
            gout381 += (g60) * (2*beta*g103) * (C00z) * weight0;
            gout382 += (g6) * (2*beta*g154) * (C00z) * weight0;
            gout383 += (g6) * (2*beta*g103) * (g221) * weight0;
            gout384 += (g60) * (2*beta*g96) * (g180) * weight0;
            gout385 += (g6) * (2*beta*g148) * (g180) * weight0;
            gout386 += (g6) * (2*beta*g96) * (g231) * weight0;
            gout387 += (g48) * (-1 + 2*beta*g117) * (C00z) * weight0;
            gout388 += (D00x) * (-g131 + 2*beta*g165) * (C00z) * weight0;
            gout389 += (D00x) * (-1 + 2*beta*g117) * (g221) * weight0;
            gout390 += (g42) * (-D00y + 2*beta*g123) * (C00z) * weight0;
            gout391 += (-g137 + 2*beta*g172) * (C00z) * weight0;
            gout392 += (-D00y + 2*beta*g123) * (g221) * weight0;
            gout393 += (g42) * (-1 + 2*beta*g117) * (g180) * weight0;
            gout394 += (-g131 + 2*beta*g165) * (g180) * weight0;
            gout395 += (-1 + 2*beta*g117) * (g231) * weight0;
            gout396 += (g48) * (2*beta*g96) * (g186) * weight0;
            gout397 += (D00x) * (2*beta*g148) * (g186) * weight0;
            gout398 += (D00x) * (2*beta*g96) * (g238) * weight0;
            gout399 += (g42) * (2*beta*g103) * (g186) * weight0;
            gout400 += (2*beta*g154) * (g186) * weight0;
            gout401 += (2*beta*g103) * (g238) * weight0;
            gout402 += (g42) * (2*beta*g96) * (g196) * weight0;
            gout403 += (2*beta*g148) * (g196) * weight0;
            gout404 += (2*beta*g96) * (g245) * weight0;
            gout405 += (g69) * (2*beta*g184) * weight0;
            gout406 += (g18) * (g131) * (2*beta*g184) * weight0;
            gout407 += (g18) * (2*beta*g236) * weight0;
            gout408 += (g62) * (D00y) * (2*beta*g184) * weight0;
            gout409 += (g8) * (g137) * (2*beta*g184) * weight0;
            gout410 += (g8) * (D00y) * (2*beta*g236) * weight0;
            gout411 += (g62) * (2*beta*g191) * weight0;
            gout412 += (g8) * (g131) * (2*beta*g191) * weight0;
            gout413 += (g8) * (2*beta*g242) * weight0;
            gout414 += (g54) * (g96) * (2*beta*g184) * weight0;
            gout415 += (g2) * (g148) * (2*beta*g184) * weight0;
            gout416 += (g2) * (g96) * (2*beta*g236) * weight0;
            gout417 += (g44) * (g103) * (2*beta*g184) * weight0;
            gout418 += (C00x) * (g154) * (2*beta*g184) * weight0;
            gout419 += (C00x) * (g103) * (2*beta*g236) * weight0;
            gout420 += (g44) * (g96) * (2*beta*g191) * weight0;
            gout421 += (C00x) * (g148) * (2*beta*g191) * weight0;
            gout422 += (C00x) * (g96) * (2*beta*g242) * weight0;
            gout423 += (g54) * (-1 + 2*beta*g205) * weight0;
            gout424 += (g2) * (g131) * (-1 + 2*beta*g205) * weight0;
            gout425 += (g2) * (-g219 + 2*beta*g253) * weight0;
            gout426 += (g44) * (D00y) * (-1 + 2*beta*g205) * weight0;
            gout427 += (C00x) * (g137) * (-1 + 2*beta*g205) * weight0;
            gout428 += (C00x) * (D00y) * (-g219 + 2*beta*g253) * weight0;
            gout429 += (g44) * (-D00z + 2*beta*g211) * weight0;
            gout430 += (C00x) * (g131) * (-D00z + 2*beta*g211) * weight0;
            gout431 += (C00x) * (-g225 + 2*beta*g260) * weight0;
            gout432 += (g66) * (C00y) * (2*beta*g184) * weight0;
            gout433 += (g13) * (g133) * (2*beta*g184) * weight0;
            gout434 += (g13) * (C00y) * (2*beta*g236) * weight0;
            gout435 += (g60) * (g92) * (2*beta*g184) * weight0;
            gout436 += (g6) * (g143) * (2*beta*g184) * weight0;
            gout437 += (g6) * (g92) * (2*beta*g236) * weight0;
            gout438 += (g60) * (C00y) * (2*beta*g191) * weight0;
            gout439 += (g6) * (g133) * (2*beta*g191) * weight0;
            gout440 += (g6) * (C00y) * (2*beta*g242) * weight0;
            gout441 += (g48) * (g98) * (2*beta*g184) * weight0;
            gout442 += (D00x) * (g150) * (2*beta*g184) * weight0;
            gout443 += (D00x) * (g98) * (2*beta*g236) * weight0;
            gout444 += (g42) * (g108) * (2*beta*g184) * weight0;
            gout445 += (g157) * (2*beta*g184) * weight0;
            gout446 += (g108) * (2*beta*g236) * weight0;
            gout447 += (g42) * (g98) * (2*beta*g191) * weight0;
            gout448 += (g150) * (2*beta*g191) * weight0;
            gout449 += (g98) * (2*beta*g242) * weight0;
            gout450 += (g48) * (C00y) * (-1 + 2*beta*g205) * weight0;
            gout451 += (D00x) * (g133) * (-1 + 2*beta*g205) * weight0;
            gout452 += (D00x) * (C00y) * (-g219 + 2*beta*g253) * weight0;
            gout453 += (g42) * (g92) * (-1 + 2*beta*g205) * weight0;
            gout454 += (g143) * (-1 + 2*beta*g205) * weight0;
            gout455 += (g92) * (-g219 + 2*beta*g253) * weight0;
            gout456 += (g42) * (C00y) * (-D00z + 2*beta*g211) * weight0;
            gout457 += (g133) * (-D00z + 2*beta*g211) * weight0;
            gout458 += (C00y) * (-g225 + 2*beta*g260) * weight0;
            gout459 += (g66) * (2*beta*g186) * weight0;
            gout460 += (g13) * (g131) * (2*beta*g186) * weight0;
            gout461 += (g13) * (2*beta*g238) * weight0;
            gout462 += (g60) * (D00y) * (2*beta*g186) * weight0;
            gout463 += (g6) * (g137) * (2*beta*g186) * weight0;
            gout464 += (g6) * (D00y) * (2*beta*g238) * weight0;
            gout465 += (g60) * (2*beta*g196) * weight0;
            gout466 += (g6) * (g131) * (2*beta*g196) * weight0;
            gout467 += (g6) * (2*beta*g245) * weight0;
            gout468 += (g48) * (g96) * (2*beta*g186) * weight0;
            gout469 += (D00x) * (g148) * (2*beta*g186) * weight0;
            gout470 += (D00x) * (g96) * (2*beta*g238) * weight0;
            gout471 += (g42) * (g103) * (2*beta*g186) * weight0;
            gout472 += (g154) * (2*beta*g186) * weight0;
            gout473 += (g103) * (2*beta*g238) * weight0;
            gout474 += (g42) * (g96) * (2*beta*g196) * weight0;
            gout475 += (g148) * (2*beta*g196) * weight0;
            gout476 += (g96) * (2*beta*g245) * weight0;
            gout477 += (g48) * (-C00z + 2*beta*g208) * weight0;
            gout478 += (D00x) * (g131) * (-C00z + 2*beta*g208) * weight0;
            gout479 += (D00x) * (-g221 + 2*beta*g257) * weight0;
            gout480 += (g42) * (D00y) * (-C00z + 2*beta*g208) * weight0;
            gout481 += (g137) * (-C00z + 2*beta*g208) * weight0;
            gout482 += (D00y) * (-g221 + 2*beta*g257) * weight0;
            gout483 += (g42) * (-g180 + 2*beta*g218) * weight0;
            gout484 += (g131) * (-g180 + 2*beta*g218) * weight0;
            gout485 += (-g231 + 2*beta*g265) * weight0;
        }
    } }

    int *ao_loc = c_bpcache.ao_loc;
    int i0 = ao_loc[ish];
    int j0 = ao_loc[jsh];
    int k0 = ao_loc[ksh];
    int l0 = ao_loc[lsh];
    int n_dm = jk.n_dm;
    int nao = jk.nao;
    size_t nao2 = nao * nao;
    double* __restrict__ dm = jk.dm;
    double *vj = jk.vj;
    double *vk = jk.vk;
    double d_0, d_1, d_2, d_3, d_4, d_5, d_6, d_7, d_8;

    for (int i_dm = 0; i_dm < n_dm; ++i_dm) {
        if (vj != NULL) {
            d_0 = dm[(k0+0)+nao*(l0+0)];
            d_1 = dm[(k0+0)+nao*(l0+1)];
            d_2 = dm[(k0+0)+nao*(l0+2)];
            d_3 = dm[(k0+1)+nao*(l0+0)];
            d_4 = dm[(k0+1)+nao*(l0+1)];
            d_5 = dm[(k0+1)+nao*(l0+2)];
            d_6 = dm[(k0+2)+nao*(l0+0)];
            d_7 = dm[(k0+2)+nao*(l0+1)];
            d_8 = dm[(k0+2)+nao*(l0+2)];
            atomicAdd(vj+(i0+0)+nao*(j0+0), gout0*d_0+gout1*d_1+gout2*d_2+gout3*d_3+gout4*d_4+gout5*d_5+gout6*d_6+gout7*d_7+gout8*d_8);
            atomicAdd(vj+(i0+0)+nao*(j0+1), gout9*d_0+gout10*d_1+gout11*d_2+gout12*d_3+gout13*d_4+gout14*d_5+gout15*d_6+gout16*d_7+gout17*d_8);
            atomicAdd(vj+(i0+0)+nao*(j0+2), gout18*d_0+gout19*d_1+gout20*d_2+gout21*d_3+gout22*d_4+gout23*d_5+gout24*d_6+gout25*d_7+gout26*d_8);
            atomicAdd(vj+(i0+1)+nao*(j0+0), gout27*d_0+gout28*d_1+gout29*d_2+gout30*d_3+gout31*d_4+gout32*d_5+gout33*d_6+gout34*d_7+gout35*d_8);
            atomicAdd(vj+(i0+1)+nao*(j0+1), gout36*d_0+gout37*d_1+gout38*d_2+gout39*d_3+gout40*d_4+gout41*d_5+gout42*d_6+gout43*d_7+gout44*d_8);
            atomicAdd(vj+(i0+1)+nao*(j0+2), gout45*d_0+gout46*d_1+gout47*d_2+gout48*d_3+gout49*d_4+gout50*d_5+gout51*d_6+gout52*d_7+gout53*d_8);
            atomicAdd(vj+(i0+2)+nao*(j0+0), gout54*d_0+gout55*d_1+gout56*d_2+gout57*d_3+gout58*d_4+gout59*d_5+gout60*d_6+gout61*d_7+gout62*d_8);
            atomicAdd(vj+(i0+2)+nao*(j0+1), gout63*d_0+gout64*d_1+gout65*d_2+gout66*d_3+gout67*d_4+gout68*d_5+gout69*d_6+gout70*d_7+gout71*d_8);
            atomicAdd(vj+(i0+2)+nao*(j0+2), gout72*d_0+gout73*d_1+gout74*d_2+gout75*d_3+gout76*d_4+gout77*d_5+gout78*d_6+gout79*d_7+gout80*d_8);
            atomicAdd(vj+(i0+0)+nao*(j0+0)+nao2, gout81*d_0+gout82*d_1+gout83*d_2+gout84*d_3+gout85*d_4+gout86*d_5+gout87*d_6+gout88*d_7+gout89*d_8);
            atomicAdd(vj+(i0+0)+nao*(j0+1)+nao2, gout90*d_0+gout91*d_1+gout92*d_2+gout93*d_3+gout94*d_4+gout95*d_5+gout96*d_6+gout97*d_7+gout98*d_8);
            atomicAdd(vj+(i0+0)+nao*(j0+2)+nao2, gout99*d_0+gout100*d_1+gout101*d_2+gout102*d_3+gout103*d_4+gout104*d_5+gout105*d_6+gout106*d_7+gout107*d_8);
            atomicAdd(vj+(i0+1)+nao*(j0+0)+nao2, gout108*d_0+gout109*d_1+gout110*d_2+gout111*d_3+gout112*d_4+gout113*d_5+gout114*d_6+gout115*d_7+gout116*d_8);
            atomicAdd(vj+(i0+1)+nao*(j0+1)+nao2, gout117*d_0+gout118*d_1+gout119*d_2+gout120*d_3+gout121*d_4+gout122*d_5+gout123*d_6+gout124*d_7+gout125*d_8);
            atomicAdd(vj+(i0+1)+nao*(j0+2)+nao2, gout126*d_0+gout127*d_1+gout128*d_2+gout129*d_3+gout130*d_4+gout131*d_5+gout132*d_6+gout133*d_7+gout134*d_8);
            atomicAdd(vj+(i0+2)+nao*(j0+0)+nao2, gout135*d_0+gout136*d_1+gout137*d_2+gout138*d_3+gout139*d_4+gout140*d_5+gout141*d_6+gout142*d_7+gout143*d_8);
            atomicAdd(vj+(i0+2)+nao*(j0+1)+nao2, gout144*d_0+gout145*d_1+gout146*d_2+gout147*d_3+gout148*d_4+gout149*d_5+gout150*d_6+gout151*d_7+gout152*d_8);
            atomicAdd(vj+(i0+2)+nao*(j0+2)+nao2, gout153*d_0+gout154*d_1+gout155*d_2+gout156*d_3+gout157*d_4+gout158*d_5+gout159*d_6+gout160*d_7+gout161*d_8);
            atomicAdd(vj+(i0+0)+nao*(j0+0)+2*nao2, gout162*d_0+gout163*d_1+gout164*d_2+gout165*d_3+gout166*d_4+gout167*d_5+gout168*d_6+gout169*d_7+gout170*d_8);
            atomicAdd(vj+(i0+0)+nao*(j0+1)+2*nao2, gout171*d_0+gout172*d_1+gout173*d_2+gout174*d_3+gout175*d_4+gout176*d_5+gout177*d_6+gout178*d_7+gout179*d_8);
            atomicAdd(vj+(i0+0)+nao*(j0+2)+2*nao2, gout180*d_0+gout181*d_1+gout182*d_2+gout183*d_3+gout184*d_4+gout185*d_5+gout186*d_6+gout187*d_7+gout188*d_8);
            atomicAdd(vj+(i0+1)+nao*(j0+0)+2*nao2, gout189*d_0+gout190*d_1+gout191*d_2+gout192*d_3+gout193*d_4+gout194*d_5+gout195*d_6+gout196*d_7+gout197*d_8);
            atomicAdd(vj+(i0+1)+nao*(j0+1)+2*nao2, gout198*d_0+gout199*d_1+gout200*d_2+gout201*d_3+gout202*d_4+gout203*d_5+gout204*d_6+gout205*d_7+gout206*d_8);
            atomicAdd(vj+(i0+1)+nao*(j0+2)+2*nao2, gout207*d_0+gout208*d_1+gout209*d_2+gout210*d_3+gout211*d_4+gout212*d_5+gout213*d_6+gout214*d_7+gout215*d_8);
            atomicAdd(vj+(i0+2)+nao*(j0+0)+2*nao2, gout216*d_0+gout217*d_1+gout218*d_2+gout219*d_3+gout220*d_4+gout221*d_5+gout222*d_6+gout223*d_7+gout224*d_8);
            atomicAdd(vj+(i0+2)+nao*(j0+1)+2*nao2, gout225*d_0+gout226*d_1+gout227*d_2+gout228*d_3+gout229*d_4+gout230*d_5+gout231*d_6+gout232*d_7+gout233*d_8);
            atomicAdd(vj+(i0+2)+nao*(j0+2)+2*nao2, gout234*d_0+gout235*d_1+gout236*d_2+gout237*d_3+gout238*d_4+gout239*d_5+gout240*d_6+gout241*d_7+gout242*d_8);
            atomicAdd(vj+nao*(i0+0)+(j0+0), gout243*d_0+gout244*d_1+gout245*d_2+gout246*d_3+gout247*d_4+gout248*d_5+gout249*d_6+gout250*d_7+gout251*d_8);
            atomicAdd(vj+nao*(i0+0)+(j0+1), gout252*d_0+gout253*d_1+gout254*d_2+gout255*d_3+gout256*d_4+gout257*d_5+gout258*d_6+gout259*d_7+gout260*d_8);
            atomicAdd(vj+nao*(i0+0)+(j0+2), gout261*d_0+gout262*d_1+gout263*d_2+gout264*d_3+gout265*d_4+gout266*d_5+gout267*d_6+gout268*d_7+gout269*d_8);
            atomicAdd(vj+nao*(i0+1)+(j0+0), gout270*d_0+gout271*d_1+gout272*d_2+gout273*d_3+gout274*d_4+gout275*d_5+gout276*d_6+gout277*d_7+gout278*d_8);
            atomicAdd(vj+nao*(i0+1)+(j0+1), gout279*d_0+gout280*d_1+gout281*d_2+gout282*d_3+gout283*d_4+gout284*d_5+gout285*d_6+gout286*d_7+gout287*d_8);
            atomicAdd(vj+nao*(i0+1)+(j0+2), gout288*d_0+gout289*d_1+gout290*d_2+gout291*d_3+gout292*d_4+gout293*d_5+gout294*d_6+gout295*d_7+gout296*d_8);
            atomicAdd(vj+nao*(i0+2)+(j0+0), gout297*d_0+gout298*d_1+gout299*d_2+gout300*d_3+gout301*d_4+gout302*d_5+gout303*d_6+gout304*d_7+gout305*d_8);
            atomicAdd(vj+nao*(i0+2)+(j0+1), gout306*d_0+gout307*d_1+gout308*d_2+gout309*d_3+gout310*d_4+gout311*d_5+gout312*d_6+gout313*d_7+gout314*d_8);
            atomicAdd(vj+nao*(i0+2)+(j0+2), gout315*d_0+gout316*d_1+gout317*d_2+gout318*d_3+gout319*d_4+gout320*d_5+gout321*d_6+gout322*d_7+gout323*d_8);
            atomicAdd(vj+nao*(i0+0)+(j0+0)+nao2, gout324*d_0+gout325*d_1+gout326*d_2+gout327*d_3+gout328*d_4+gout329*d_5+gout330*d_6+gout331*d_7+gout332*d_8);
            atomicAdd(vj+nao*(i0+0)+(j0+1)+nao2, gout333*d_0+gout334*d_1+gout335*d_2+gout336*d_3+gout337*d_4+gout338*d_5+gout339*d_6+gout340*d_7+gout341*d_8);
            atomicAdd(vj+nao*(i0+0)+(j0+2)+nao2, gout342*d_0+gout343*d_1+gout344*d_2+gout345*d_3+gout346*d_4+gout347*d_5+gout348*d_6+gout349*d_7+gout350*d_8);
            atomicAdd(vj+nao*(i0+1)+(j0+0)+nao2, gout351*d_0+gout352*d_1+gout353*d_2+gout354*d_3+gout355*d_4+gout356*d_5+gout357*d_6+gout358*d_7+gout359*d_8);
            atomicAdd(vj+nao*(i0+1)+(j0+1)+nao2, gout360*d_0+gout361*d_1+gout362*d_2+gout363*d_3+gout364*d_4+gout365*d_5+gout366*d_6+gout367*d_7+gout368*d_8);
            atomicAdd(vj+nao*(i0+1)+(j0+2)+nao2, gout369*d_0+gout370*d_1+gout371*d_2+gout372*d_3+gout373*d_4+gout374*d_5+gout375*d_6+gout376*d_7+gout377*d_8);
            atomicAdd(vj+nao*(i0+2)+(j0+0)+nao2, gout378*d_0+gout379*d_1+gout380*d_2+gout381*d_3+gout382*d_4+gout383*d_5+gout384*d_6+gout385*d_7+gout386*d_8);
            atomicAdd(vj+nao*(i0+2)+(j0+1)+nao2, gout387*d_0+gout388*d_1+gout389*d_2+gout390*d_3+gout391*d_4+gout392*d_5+gout393*d_6+gout394*d_7+gout395*d_8);
            atomicAdd(vj+nao*(i0+2)+(j0+2)+nao2, gout396*d_0+gout397*d_1+gout398*d_2+gout399*d_3+gout400*d_4+gout401*d_5+gout402*d_6+gout403*d_7+gout404*d_8);
            atomicAdd(vj+nao*(i0+0)+(j0+0)+2*nao2, gout405*d_0+gout406*d_1+gout407*d_2+gout408*d_3+gout409*d_4+gout410*d_5+gout411*d_6+gout412*d_7+gout413*d_8);
            atomicAdd(vj+nao*(i0+0)+(j0+1)+2*nao2, gout414*d_0+gout415*d_1+gout416*d_2+gout417*d_3+gout418*d_4+gout419*d_5+gout420*d_6+gout421*d_7+gout422*d_8);
            atomicAdd(vj+nao*(i0+0)+(j0+2)+2*nao2, gout423*d_0+gout424*d_1+gout425*d_2+gout426*d_3+gout427*d_4+gout428*d_5+gout429*d_6+gout430*d_7+gout431*d_8);
            atomicAdd(vj+nao*(i0+1)+(j0+0)+2*nao2, gout432*d_0+gout433*d_1+gout434*d_2+gout435*d_3+gout436*d_4+gout437*d_5+gout438*d_6+gout439*d_7+gout440*d_8);
            atomicAdd(vj+nao*(i0+1)+(j0+1)+2*nao2, gout441*d_0+gout442*d_1+gout443*d_2+gout444*d_3+gout445*d_4+gout446*d_5+gout447*d_6+gout448*d_7+gout449*d_8);
            atomicAdd(vj+nao*(i0+1)+(j0+2)+2*nao2, gout450*d_0+gout451*d_1+gout452*d_2+gout453*d_3+gout454*d_4+gout455*d_5+gout456*d_6+gout457*d_7+gout458*d_8);
            atomicAdd(vj+nao*(i0+2)+(j0+0)+2*nao2, gout459*d_0+gout460*d_1+gout461*d_2+gout462*d_3+gout463*d_4+gout464*d_5+gout465*d_6+gout466*d_7+gout467*d_8);
            atomicAdd(vj+nao*(i0+2)+(j0+1)+2*nao2, gout468*d_0+gout469*d_1+gout470*d_2+gout471*d_3+gout472*d_4+gout473*d_5+gout474*d_6+gout475*d_7+gout476*d_8);
            atomicAdd(vj+nao*(i0+2)+(j0+2)+2*nao2, gout477*d_0+gout478*d_1+gout479*d_2+gout480*d_3+gout481*d_4+gout482*d_5+gout483*d_6+gout484*d_7+gout485*d_8);
            vj += 3*nao2;
        }
        if (vk != NULL) {
            // ijkl, jk -> il
            d_0 = dm[(j0+0)+nao*(k0+0)];
            d_1 = dm[(j0+0)+nao*(k0+1)];
            d_2 = dm[(j0+0)+nao*(k0+2)];
            d_3 = dm[(j0+1)+nao*(k0+0)];
            d_4 = dm[(j0+1)+nao*(k0+1)];
            d_5 = dm[(j0+1)+nao*(k0+2)];
            d_6 = dm[(j0+2)+nao*(k0+0)];
            d_7 = dm[(j0+2)+nao*(k0+1)];
            d_8 = dm[(j0+2)+nao*(k0+2)];
            atomicAdd(vk+(i0+0)+nao*(l0+0), gout0*d_0+gout3*d_1+gout6*d_2+gout9*d_3+gout12*d_4+gout15*d_5+gout18*d_6+gout21*d_7+gout24*d_8);
            atomicAdd(vk+(i0+0)+nao*(l0+1), gout1*d_0+gout4*d_1+gout7*d_2+gout10*d_3+gout13*d_4+gout16*d_5+gout19*d_6+gout22*d_7+gout25*d_8);
            atomicAdd(vk+(i0+0)+nao*(l0+2), gout2*d_0+gout5*d_1+gout8*d_2+gout11*d_3+gout14*d_4+gout17*d_5+gout20*d_6+gout23*d_7+gout26*d_8);
            atomicAdd(vk+(i0+1)+nao*(l0+0), gout27*d_0+gout30*d_1+gout33*d_2+gout36*d_3+gout39*d_4+gout42*d_5+gout45*d_6+gout48*d_7+gout51*d_8);
            atomicAdd(vk+(i0+1)+nao*(l0+1), gout28*d_0+gout31*d_1+gout34*d_2+gout37*d_3+gout40*d_4+gout43*d_5+gout46*d_6+gout49*d_7+gout52*d_8);
            atomicAdd(vk+(i0+1)+nao*(l0+2), gout29*d_0+gout32*d_1+gout35*d_2+gout38*d_3+gout41*d_4+gout44*d_5+gout47*d_6+gout50*d_7+gout53*d_8);
            atomicAdd(vk+(i0+2)+nao*(l0+0), gout54*d_0+gout57*d_1+gout60*d_2+gout63*d_3+gout66*d_4+gout69*d_5+gout72*d_6+gout75*d_7+gout78*d_8);
            atomicAdd(vk+(i0+2)+nao*(l0+1), gout55*d_0+gout58*d_1+gout61*d_2+gout64*d_3+gout67*d_4+gout70*d_5+gout73*d_6+gout76*d_7+gout79*d_8);
            atomicAdd(vk+(i0+2)+nao*(l0+2), gout56*d_0+gout59*d_1+gout62*d_2+gout65*d_3+gout68*d_4+gout71*d_5+gout74*d_6+gout77*d_7+gout80*d_8);
            atomicAdd(vk+(i0+0)+nao*(l0+0)+nao2, gout81*d_0+gout84*d_1+gout87*d_2+gout90*d_3+gout93*d_4+gout96*d_5+gout99*d_6+gout102*d_7+gout105*d_8);
            atomicAdd(vk+(i0+0)+nao*(l0+1)+nao2, gout82*d_0+gout85*d_1+gout88*d_2+gout91*d_3+gout94*d_4+gout97*d_5+gout100*d_6+gout103*d_7+gout106*d_8);
            atomicAdd(vk+(i0+0)+nao*(l0+2)+nao2, gout83*d_0+gout86*d_1+gout89*d_2+gout92*d_3+gout95*d_4+gout98*d_5+gout101*d_6+gout104*d_7+gout107*d_8);
            atomicAdd(vk+(i0+1)+nao*(l0+0)+nao2, gout108*d_0+gout111*d_1+gout114*d_2+gout117*d_3+gout120*d_4+gout123*d_5+gout126*d_6+gout129*d_7+gout132*d_8);
            atomicAdd(vk+(i0+1)+nao*(l0+1)+nao2, gout109*d_0+gout112*d_1+gout115*d_2+gout118*d_3+gout121*d_4+gout124*d_5+gout127*d_6+gout130*d_7+gout133*d_8);
            atomicAdd(vk+(i0+1)+nao*(l0+2)+nao2, gout110*d_0+gout113*d_1+gout116*d_2+gout119*d_3+gout122*d_4+gout125*d_5+gout128*d_6+gout131*d_7+gout134*d_8);
            atomicAdd(vk+(i0+2)+nao*(l0+0)+nao2, gout135*d_0+gout138*d_1+gout141*d_2+gout144*d_3+gout147*d_4+gout150*d_5+gout153*d_6+gout156*d_7+gout159*d_8);
            atomicAdd(vk+(i0+2)+nao*(l0+1)+nao2, gout136*d_0+gout139*d_1+gout142*d_2+gout145*d_3+gout148*d_4+gout151*d_5+gout154*d_6+gout157*d_7+gout160*d_8);
            atomicAdd(vk+(i0+2)+nao*(l0+2)+nao2, gout137*d_0+gout140*d_1+gout143*d_2+gout146*d_3+gout149*d_4+gout152*d_5+gout155*d_6+gout158*d_7+gout161*d_8);
            atomicAdd(vk+(i0+0)+nao*(l0+0)+2*nao2, gout162*d_0+gout165*d_1+gout168*d_2+gout171*d_3+gout174*d_4+gout177*d_5+gout180*d_6+gout183*d_7+gout186*d_8);
            atomicAdd(vk+(i0+0)+nao*(l0+1)+2*nao2, gout163*d_0+gout166*d_1+gout169*d_2+gout172*d_3+gout175*d_4+gout178*d_5+gout181*d_6+gout184*d_7+gout187*d_8);
            atomicAdd(vk+(i0+0)+nao*(l0+2)+2*nao2, gout164*d_0+gout167*d_1+gout170*d_2+gout173*d_3+gout176*d_4+gout179*d_5+gout182*d_6+gout185*d_7+gout188*d_8);
            atomicAdd(vk+(i0+1)+nao*(l0+0)+2*nao2, gout189*d_0+gout192*d_1+gout195*d_2+gout198*d_3+gout201*d_4+gout204*d_5+gout207*d_6+gout210*d_7+gout213*d_8);
            atomicAdd(vk+(i0+1)+nao*(l0+1)+2*nao2, gout190*d_0+gout193*d_1+gout196*d_2+gout199*d_3+gout202*d_4+gout205*d_5+gout208*d_6+gout211*d_7+gout214*d_8);
            atomicAdd(vk+(i0+1)+nao*(l0+2)+2*nao2, gout191*d_0+gout194*d_1+gout197*d_2+gout200*d_3+gout203*d_4+gout206*d_5+gout209*d_6+gout212*d_7+gout215*d_8);
            atomicAdd(vk+(i0+2)+nao*(l0+0)+2*nao2, gout216*d_0+gout219*d_1+gout222*d_2+gout225*d_3+gout228*d_4+gout231*d_5+gout234*d_6+gout237*d_7+gout240*d_8);
            atomicAdd(vk+(i0+2)+nao*(l0+1)+2*nao2, gout217*d_0+gout220*d_1+gout223*d_2+gout226*d_3+gout229*d_4+gout232*d_5+gout235*d_6+gout238*d_7+gout241*d_8);
            atomicAdd(vk+(i0+2)+nao*(l0+2)+2*nao2, gout218*d_0+gout221*d_1+gout224*d_2+gout227*d_3+gout230*d_4+gout233*d_5+gout236*d_6+gout239*d_7+gout242*d_8);
            // ijkl, jl -> ik
            d_0 = dm[(j0+0)+nao*(l0+0)];
            d_1 = dm[(j0+0)+nao*(l0+1)];
            d_2 = dm[(j0+0)+nao*(l0+2)];
            d_3 = dm[(j0+1)+nao*(l0+0)];
            d_4 = dm[(j0+1)+nao*(l0+1)];
            d_5 = dm[(j0+1)+nao*(l0+2)];
            d_6 = dm[(j0+2)+nao*(l0+0)];
            d_7 = dm[(j0+2)+nao*(l0+1)];
            d_8 = dm[(j0+2)+nao*(l0+2)];
            atomicAdd(vk+(i0+0)+nao*(k0+0), gout0*d_0+gout1*d_1+gout2*d_2+gout9*d_3+gout10*d_4+gout11*d_5+gout18*d_6+gout19*d_7+gout20*d_8);
            atomicAdd(vk+(i0+0)+nao*(k0+1), gout3*d_0+gout4*d_1+gout5*d_2+gout12*d_3+gout13*d_4+gout14*d_5+gout21*d_6+gout22*d_7+gout23*d_8);
            atomicAdd(vk+(i0+0)+nao*(k0+2), gout6*d_0+gout7*d_1+gout8*d_2+gout15*d_3+gout16*d_4+gout17*d_5+gout24*d_6+gout25*d_7+gout26*d_8);
            atomicAdd(vk+(i0+1)+nao*(k0+0), gout27*d_0+gout28*d_1+gout29*d_2+gout36*d_3+gout37*d_4+gout38*d_5+gout45*d_6+gout46*d_7+gout47*d_8);
            atomicAdd(vk+(i0+1)+nao*(k0+1), gout30*d_0+gout31*d_1+gout32*d_2+gout39*d_3+gout40*d_4+gout41*d_5+gout48*d_6+gout49*d_7+gout50*d_8);
            atomicAdd(vk+(i0+1)+nao*(k0+2), gout33*d_0+gout34*d_1+gout35*d_2+gout42*d_3+gout43*d_4+gout44*d_5+gout51*d_6+gout52*d_7+gout53*d_8);
            atomicAdd(vk+(i0+2)+nao*(k0+0), gout54*d_0+gout55*d_1+gout56*d_2+gout63*d_3+gout64*d_4+gout65*d_5+gout72*d_6+gout73*d_7+gout74*d_8);
            atomicAdd(vk+(i0+2)+nao*(k0+1), gout57*d_0+gout58*d_1+gout59*d_2+gout66*d_3+gout67*d_4+gout68*d_5+gout75*d_6+gout76*d_7+gout77*d_8);
            atomicAdd(vk+(i0+2)+nao*(k0+2), gout60*d_0+gout61*d_1+gout62*d_2+gout69*d_3+gout70*d_4+gout71*d_5+gout78*d_6+gout79*d_7+gout80*d_8);
            atomicAdd(vk+(i0+0)+nao*(k0+0)+nao2, gout81*d_0+gout82*d_1+gout83*d_2+gout90*d_3+gout91*d_4+gout92*d_5+gout99*d_6+gout100*d_7+gout101*d_8);
            atomicAdd(vk+(i0+0)+nao*(k0+1)+nao2, gout84*d_0+gout85*d_1+gout86*d_2+gout93*d_3+gout94*d_4+gout95*d_5+gout102*d_6+gout103*d_7+gout104*d_8);
            atomicAdd(vk+(i0+0)+nao*(k0+2)+nao2, gout87*d_0+gout88*d_1+gout89*d_2+gout96*d_3+gout97*d_4+gout98*d_5+gout105*d_6+gout106*d_7+gout107*d_8);
            atomicAdd(vk+(i0+1)+nao*(k0+0)+nao2, gout108*d_0+gout109*d_1+gout110*d_2+gout117*d_3+gout118*d_4+gout119*d_5+gout126*d_6+gout127*d_7+gout128*d_8);
            atomicAdd(vk+(i0+1)+nao*(k0+1)+nao2, gout111*d_0+gout112*d_1+gout113*d_2+gout120*d_3+gout121*d_4+gout122*d_5+gout129*d_6+gout130*d_7+gout131*d_8);
            atomicAdd(vk+(i0+1)+nao*(k0+2)+nao2, gout114*d_0+gout115*d_1+gout116*d_2+gout123*d_3+gout124*d_4+gout125*d_5+gout132*d_6+gout133*d_7+gout134*d_8);
            atomicAdd(vk+(i0+2)+nao*(k0+0)+nao2, gout135*d_0+gout136*d_1+gout137*d_2+gout144*d_3+gout145*d_4+gout146*d_5+gout153*d_6+gout154*d_7+gout155*d_8);
            atomicAdd(vk+(i0+2)+nao*(k0+1)+nao2, gout138*d_0+gout139*d_1+gout140*d_2+gout147*d_3+gout148*d_4+gout149*d_5+gout156*d_6+gout157*d_7+gout158*d_8);
            atomicAdd(vk+(i0+2)+nao*(k0+2)+nao2, gout141*d_0+gout142*d_1+gout143*d_2+gout150*d_3+gout151*d_4+gout152*d_5+gout159*d_6+gout160*d_7+gout161*d_8);
            atomicAdd(vk+(i0+0)+nao*(k0+0)+2*nao2, gout162*d_0+gout163*d_1+gout164*d_2+gout171*d_3+gout172*d_4+gout173*d_5+gout180*d_6+gout181*d_7+gout182*d_8);
            atomicAdd(vk+(i0+0)+nao*(k0+1)+2*nao2, gout165*d_0+gout166*d_1+gout167*d_2+gout174*d_3+gout175*d_4+gout176*d_5+gout183*d_6+gout184*d_7+gout185*d_8);
            atomicAdd(vk+(i0+0)+nao*(k0+2)+2*nao2, gout168*d_0+gout169*d_1+gout170*d_2+gout177*d_3+gout178*d_4+gout179*d_5+gout186*d_6+gout187*d_7+gout188*d_8);
            atomicAdd(vk+(i0+1)+nao*(k0+0)+2*nao2, gout189*d_0+gout190*d_1+gout191*d_2+gout198*d_3+gout199*d_4+gout200*d_5+gout207*d_6+gout208*d_7+gout209*d_8);
            atomicAdd(vk+(i0+1)+nao*(k0+1)+2*nao2, gout192*d_0+gout193*d_1+gout194*d_2+gout201*d_3+gout202*d_4+gout203*d_5+gout210*d_6+gout211*d_7+gout212*d_8);
            atomicAdd(vk+(i0+1)+nao*(k0+2)+2*nao2, gout195*d_0+gout196*d_1+gout197*d_2+gout204*d_3+gout205*d_4+gout206*d_5+gout213*d_6+gout214*d_7+gout215*d_8);
            atomicAdd(vk+(i0+2)+nao*(k0+0)+2*nao2, gout216*d_0+gout217*d_1+gout218*d_2+gout225*d_3+gout226*d_4+gout227*d_5+gout234*d_6+gout235*d_7+gout236*d_8);
            atomicAdd(vk+(i0+2)+nao*(k0+1)+2*nao2, gout219*d_0+gout220*d_1+gout221*d_2+gout228*d_3+gout229*d_4+gout230*d_5+gout237*d_6+gout238*d_7+gout239*d_8);
            atomicAdd(vk+(i0+2)+nao*(k0+2)+2*nao2, gout222*d_0+gout223*d_1+gout224*d_2+gout231*d_3+gout232*d_4+gout233*d_5+gout240*d_6+gout241*d_7+gout242*d_8);
            // ijkl, ik -> jl
            d_0 = dm[(i0+0)+nao*(k0+0)];
            d_1 = dm[(i0+0)+nao*(k0+1)];
            d_2 = dm[(i0+0)+nao*(k0+2)];
            d_3 = dm[(i0+1)+nao*(k0+0)];
            d_4 = dm[(i0+1)+nao*(k0+1)];
            d_5 = dm[(i0+1)+nao*(k0+2)];
            d_6 = dm[(i0+2)+nao*(k0+0)];
            d_7 = dm[(i0+2)+nao*(k0+1)];
            d_8 = dm[(i0+2)+nao*(k0+2)];
            atomicAdd(vk+(j0+0)+nao*(l0+0), gout243*d_0+gout246*d_1+gout249*d_2+gout270*d_3+gout273*d_4+gout276*d_5+gout297*d_6+gout300*d_7+gout303*d_8);
            atomicAdd(vk+(j0+0)+nao*(l0+1), gout244*d_0+gout247*d_1+gout250*d_2+gout271*d_3+gout274*d_4+gout277*d_5+gout298*d_6+gout301*d_7+gout304*d_8);
            atomicAdd(vk+(j0+0)+nao*(l0+2), gout245*d_0+gout248*d_1+gout251*d_2+gout272*d_3+gout275*d_4+gout278*d_5+gout299*d_6+gout302*d_7+gout305*d_8);
            atomicAdd(vk+(j0+1)+nao*(l0+0), gout252*d_0+gout255*d_1+gout258*d_2+gout279*d_3+gout282*d_4+gout285*d_5+gout306*d_6+gout309*d_7+gout312*d_8);
            atomicAdd(vk+(j0+1)+nao*(l0+1), gout253*d_0+gout256*d_1+gout259*d_2+gout280*d_3+gout283*d_4+gout286*d_5+gout307*d_6+gout310*d_7+gout313*d_8);
            atomicAdd(vk+(j0+1)+nao*(l0+2), gout254*d_0+gout257*d_1+gout260*d_2+gout281*d_3+gout284*d_4+gout287*d_5+gout308*d_6+gout311*d_7+gout314*d_8);
            atomicAdd(vk+(j0+2)+nao*(l0+0), gout261*d_0+gout264*d_1+gout267*d_2+gout288*d_3+gout291*d_4+gout294*d_5+gout315*d_6+gout318*d_7+gout321*d_8);
            atomicAdd(vk+(j0+2)+nao*(l0+1), gout262*d_0+gout265*d_1+gout268*d_2+gout289*d_3+gout292*d_4+gout295*d_5+gout316*d_6+gout319*d_7+gout322*d_8);
            atomicAdd(vk+(j0+2)+nao*(l0+2), gout263*d_0+gout266*d_1+gout269*d_2+gout290*d_3+gout293*d_4+gout296*d_5+gout317*d_6+gout320*d_7+gout323*d_8);
            atomicAdd(vk+(j0+0)+nao*(l0+0)+nao2, gout324*d_0+gout327*d_1+gout330*d_2+gout351*d_3+gout354*d_4+gout357*d_5+gout378*d_6+gout381*d_7+gout384*d_8);
            atomicAdd(vk+(j0+0)+nao*(l0+1)+nao2, gout325*d_0+gout328*d_1+gout331*d_2+gout352*d_3+gout355*d_4+gout358*d_5+gout379*d_6+gout382*d_7+gout385*d_8);
            atomicAdd(vk+(j0+0)+nao*(l0+2)+nao2, gout326*d_0+gout329*d_1+gout332*d_2+gout353*d_3+gout356*d_4+gout359*d_5+gout380*d_6+gout383*d_7+gout386*d_8);
            atomicAdd(vk+(j0+1)+nao*(l0+0)+nao2, gout333*d_0+gout336*d_1+gout339*d_2+gout360*d_3+gout363*d_4+gout366*d_5+gout387*d_6+gout390*d_7+gout393*d_8);
            atomicAdd(vk+(j0+1)+nao*(l0+1)+nao2, gout334*d_0+gout337*d_1+gout340*d_2+gout361*d_3+gout364*d_4+gout367*d_5+gout388*d_6+gout391*d_7+gout394*d_8);
            atomicAdd(vk+(j0+1)+nao*(l0+2)+nao2, gout335*d_0+gout338*d_1+gout341*d_2+gout362*d_3+gout365*d_4+gout368*d_5+gout389*d_6+gout392*d_7+gout395*d_8);
            atomicAdd(vk+(j0+2)+nao*(l0+0)+nao2, gout342*d_0+gout345*d_1+gout348*d_2+gout369*d_3+gout372*d_4+gout375*d_5+gout396*d_6+gout399*d_7+gout402*d_8);
            atomicAdd(vk+(j0+2)+nao*(l0+1)+nao2, gout343*d_0+gout346*d_1+gout349*d_2+gout370*d_3+gout373*d_4+gout376*d_5+gout397*d_6+gout400*d_7+gout403*d_8);
            atomicAdd(vk+(j0+2)+nao*(l0+2)+nao2, gout344*d_0+gout347*d_1+gout350*d_2+gout371*d_3+gout374*d_4+gout377*d_5+gout398*d_6+gout401*d_7+gout404*d_8);
            atomicAdd(vk+(j0+0)+nao*(l0+0)+2*nao2, gout405*d_0+gout408*d_1+gout411*d_2+gout432*d_3+gout435*d_4+gout438*d_5+gout459*d_6+gout462*d_7+gout465*d_8);
            atomicAdd(vk+(j0+0)+nao*(l0+1)+2*nao2, gout406*d_0+gout409*d_1+gout412*d_2+gout433*d_3+gout436*d_4+gout439*d_5+gout460*d_6+gout463*d_7+gout466*d_8);
            atomicAdd(vk+(j0+0)+nao*(l0+2)+2*nao2, gout407*d_0+gout410*d_1+gout413*d_2+gout434*d_3+gout437*d_4+gout440*d_5+gout461*d_6+gout464*d_7+gout467*d_8);
            atomicAdd(vk+(j0+1)+nao*(l0+0)+2*nao2, gout414*d_0+gout417*d_1+gout420*d_2+gout441*d_3+gout444*d_4+gout447*d_5+gout468*d_6+gout471*d_7+gout474*d_8);
            atomicAdd(vk+(j0+1)+nao*(l0+1)+2*nao2, gout415*d_0+gout418*d_1+gout421*d_2+gout442*d_3+gout445*d_4+gout448*d_5+gout469*d_6+gout472*d_7+gout475*d_8);
            atomicAdd(vk+(j0+1)+nao*(l0+2)+2*nao2, gout416*d_0+gout419*d_1+gout422*d_2+gout443*d_3+gout446*d_4+gout449*d_5+gout470*d_6+gout473*d_7+gout476*d_8);
            atomicAdd(vk+(j0+2)+nao*(l0+0)+2*nao2, gout423*d_0+gout426*d_1+gout429*d_2+gout450*d_3+gout453*d_4+gout456*d_5+gout477*d_6+gout480*d_7+gout483*d_8);
            atomicAdd(vk+(j0+2)+nao*(l0+1)+2*nao2, gout424*d_0+gout427*d_1+gout430*d_2+gout451*d_3+gout454*d_4+gout457*d_5+gout478*d_6+gout481*d_7+gout484*d_8);
            atomicAdd(vk+(j0+2)+nao*(l0+2)+2*nao2, gout425*d_0+gout428*d_1+gout431*d_2+gout452*d_3+gout455*d_4+gout458*d_5+gout479*d_6+gout482*d_7+gout485*d_8);
            // ijkl, il -> jk
            d_0 = dm[(i0+0)+nao*(l0+0)];
            d_1 = dm[(i0+0)+nao*(l0+1)];
            d_2 = dm[(i0+0)+nao*(l0+2)];
            d_3 = dm[(i0+1)+nao*(l0+0)];
            d_4 = dm[(i0+1)+nao*(l0+1)];
            d_5 = dm[(i0+1)+nao*(l0+2)];
            d_6 = dm[(i0+2)+nao*(l0+0)];
            d_7 = dm[(i0+2)+nao*(l0+1)];
            d_8 = dm[(i0+2)+nao*(l0+2)];
            atomicAdd(vk+(j0+0)+nao*(k0+0), gout243*d_0+gout244*d_1+gout245*d_2+gout270*d_3+gout271*d_4+gout272*d_5+gout297*d_6+gout298*d_7+gout299*d_8);
            atomicAdd(vk+(j0+0)+nao*(k0+1), gout246*d_0+gout247*d_1+gout248*d_2+gout273*d_3+gout274*d_4+gout275*d_5+gout300*d_6+gout301*d_7+gout302*d_8);
            atomicAdd(vk+(j0+0)+nao*(k0+2), gout249*d_0+gout250*d_1+gout251*d_2+gout276*d_3+gout277*d_4+gout278*d_5+gout303*d_6+gout304*d_7+gout305*d_8);
            atomicAdd(vk+(j0+1)+nao*(k0+0), gout252*d_0+gout253*d_1+gout254*d_2+gout279*d_3+gout280*d_4+gout281*d_5+gout306*d_6+gout307*d_7+gout308*d_8);
            atomicAdd(vk+(j0+1)+nao*(k0+1), gout255*d_0+gout256*d_1+gout257*d_2+gout282*d_3+gout283*d_4+gout284*d_5+gout309*d_6+gout310*d_7+gout311*d_8);
            atomicAdd(vk+(j0+1)+nao*(k0+2), gout258*d_0+gout259*d_1+gout260*d_2+gout285*d_3+gout286*d_4+gout287*d_5+gout312*d_6+gout313*d_7+gout314*d_8);
            atomicAdd(vk+(j0+2)+nao*(k0+0), gout261*d_0+gout262*d_1+gout263*d_2+gout288*d_3+gout289*d_4+gout290*d_5+gout315*d_6+gout316*d_7+gout317*d_8);
            atomicAdd(vk+(j0+2)+nao*(k0+1), gout264*d_0+gout265*d_1+gout266*d_2+gout291*d_3+gout292*d_4+gout293*d_5+gout318*d_6+gout319*d_7+gout320*d_8);
            atomicAdd(vk+(j0+2)+nao*(k0+2), gout267*d_0+gout268*d_1+gout269*d_2+gout294*d_3+gout295*d_4+gout296*d_5+gout321*d_6+gout322*d_7+gout323*d_8);
            atomicAdd(vk+(j0+0)+nao*(k0+0)+nao2, gout324*d_0+gout325*d_1+gout326*d_2+gout351*d_3+gout352*d_4+gout353*d_5+gout378*d_6+gout379*d_7+gout380*d_8);
            atomicAdd(vk+(j0+0)+nao*(k0+1)+nao2, gout327*d_0+gout328*d_1+gout329*d_2+gout354*d_3+gout355*d_4+gout356*d_5+gout381*d_6+gout382*d_7+gout383*d_8);
            atomicAdd(vk+(j0+0)+nao*(k0+2)+nao2, gout330*d_0+gout331*d_1+gout332*d_2+gout357*d_3+gout358*d_4+gout359*d_5+gout384*d_6+gout385*d_7+gout386*d_8);
            atomicAdd(vk+(j0+1)+nao*(k0+0)+nao2, gout333*d_0+gout334*d_1+gout335*d_2+gout360*d_3+gout361*d_4+gout362*d_5+gout387*d_6+gout388*d_7+gout389*d_8);
            atomicAdd(vk+(j0+1)+nao*(k0+1)+nao2, gout336*d_0+gout337*d_1+gout338*d_2+gout363*d_3+gout364*d_4+gout365*d_5+gout390*d_6+gout391*d_7+gout392*d_8);
            atomicAdd(vk+(j0+1)+nao*(k0+2)+nao2, gout339*d_0+gout340*d_1+gout341*d_2+gout366*d_3+gout367*d_4+gout368*d_5+gout393*d_6+gout394*d_7+gout395*d_8);
            atomicAdd(vk+(j0+2)+nao*(k0+0)+nao2, gout342*d_0+gout343*d_1+gout344*d_2+gout369*d_3+gout370*d_4+gout371*d_5+gout396*d_6+gout397*d_7+gout398*d_8);
            atomicAdd(vk+(j0+2)+nao*(k0+1)+nao2, gout345*d_0+gout346*d_1+gout347*d_2+gout372*d_3+gout373*d_4+gout374*d_5+gout399*d_6+gout400*d_7+gout401*d_8);
            atomicAdd(vk+(j0+2)+nao*(k0+2)+nao2, gout348*d_0+gout349*d_1+gout350*d_2+gout375*d_3+gout376*d_4+gout377*d_5+gout402*d_6+gout403*d_7+gout404*d_8);
            atomicAdd(vk+(j0+0)+nao*(k0+0)+2*nao2, gout405*d_0+gout406*d_1+gout407*d_2+gout432*d_3+gout433*d_4+gout434*d_5+gout459*d_6+gout460*d_7+gout461*d_8);
            atomicAdd(vk+(j0+0)+nao*(k0+1)+2*nao2, gout408*d_0+gout409*d_1+gout410*d_2+gout435*d_3+gout436*d_4+gout437*d_5+gout462*d_6+gout463*d_7+gout464*d_8);
            atomicAdd(vk+(j0+0)+nao*(k0+2)+2*nao2, gout411*d_0+gout412*d_1+gout413*d_2+gout438*d_3+gout439*d_4+gout440*d_5+gout465*d_6+gout466*d_7+gout467*d_8);
            atomicAdd(vk+(j0+1)+nao*(k0+0)+2*nao2, gout414*d_0+gout415*d_1+gout416*d_2+gout441*d_3+gout442*d_4+gout443*d_5+gout468*d_6+gout469*d_7+gout470*d_8);
            atomicAdd(vk+(j0+1)+nao*(k0+1)+2*nao2, gout417*d_0+gout418*d_1+gout419*d_2+gout444*d_3+gout445*d_4+gout446*d_5+gout471*d_6+gout472*d_7+gout473*d_8);
            atomicAdd(vk+(j0+1)+nao*(k0+2)+2*nao2, gout420*d_0+gout421*d_1+gout422*d_2+gout447*d_3+gout448*d_4+gout449*d_5+gout474*d_6+gout475*d_7+gout476*d_8);
            atomicAdd(vk+(j0+2)+nao*(k0+0)+2*nao2, gout423*d_0+gout424*d_1+gout425*d_2+gout450*d_3+gout451*d_4+gout452*d_5+gout477*d_6+gout478*d_7+gout479*d_8);
            atomicAdd(vk+(j0+2)+nao*(k0+1)+2*nao2, gout426*d_0+gout427*d_1+gout428*d_2+gout453*d_3+gout454*d_4+gout455*d_5+gout480*d_6+gout481*d_7+gout482*d_8);
            atomicAdd(vk+(j0+2)+nao*(k0+2)+2*nao2, gout429*d_0+gout430*d_1+gout431*d_2+gout456*d_3+gout457*d_4+gout458*d_5+gout483*d_6+gout484*d_7+gout485*d_8);
            vk += 3*nao2;
        }
        dm += nao2;
    }
}

__global__
static void GINTint2e_ip1_jk_kernel_1120(GINTEnvVars envs, JKMatrix jk,
                                    BasisProdOffsets offsets)
{
    int ntasks_ij = offsets.ntasks_ij;
    int ntasks_kl = offsets.ntasks_kl;
    int task_ij = blockIdx.x * blockDim.x + threadIdx.x;
    int task_kl = blockIdx.y * blockDim.y + threadIdx.y;
    if (task_ij >= ntasks_ij || task_kl >= ntasks_kl) {
        return;
    }
    int bas_ij = offsets.bas_ij + task_ij;
    int bas_kl = offsets.bas_kl + task_kl;
    double norm = envs.fac;
    double omega = envs.omega;
    int *bas_pair2bra = c_bpcache.bas_pair2bra;
    int *bas_pair2ket = c_bpcache.bas_pair2ket;
    int ish = bas_pair2bra[bas_ij];
    int jsh = bas_pair2ket[bas_ij];
    int ksh = bas_pair2bra[bas_kl];
    int lsh = bas_pair2ket[bas_kl];
    int nprim_ij = envs.nprim_ij;
    int nprim_kl = envs.nprim_kl;
    int prim_ij = offsets.primitive_ij + task_ij * nprim_ij;
    int prim_kl = offsets.primitive_kl + task_kl * nprim_kl;

    double* __restrict__ a12 = c_bpcache.a12;
    double* __restrict__ e12 = c_bpcache.e12;
    double* __restrict__ x12 = c_bpcache.x12;
    double* __restrict__ y12 = c_bpcache.y12;
    double* __restrict__ z12 = c_bpcache.z12;
    double * __restrict__ i_exponent = c_bpcache.a1;
    double * __restrict__ j_exponent = c_bpcache.a2;

    int ij, kl;
    int prim_ij0, prim_ij1, prim_kl0, prim_kl1;
    int nbas = c_bpcache.nbas;
    double* __restrict__ bas_x = c_bpcache.bas_coords;
    double* __restrict__ bas_y = bas_x + nbas;
    double* __restrict__ bas_z = bas_y + nbas;

    double gout0 = 0;
    double gout1 = 0;
    double gout2 = 0;
    double gout3 = 0;
    double gout4 = 0;
    double gout5 = 0;
    double gout6 = 0;
    double gout7 = 0;
    double gout8 = 0;
    double gout9 = 0;
    double gout10 = 0;
    double gout11 = 0;
    double gout12 = 0;
    double gout13 = 0;
    double gout14 = 0;
    double gout15 = 0;
    double gout16 = 0;
    double gout17 = 0;
    double gout18 = 0;
    double gout19 = 0;
    double gout20 = 0;
    double gout21 = 0;
    double gout22 = 0;
    double gout23 = 0;
    double gout24 = 0;
    double gout25 = 0;
    double gout26 = 0;
    double gout27 = 0;
    double gout28 = 0;
    double gout29 = 0;
    double gout30 = 0;
    double gout31 = 0;
    double gout32 = 0;
    double gout33 = 0;
    double gout34 = 0;
    double gout35 = 0;
    double gout36 = 0;
    double gout37 = 0;
    double gout38 = 0;
    double gout39 = 0;
    double gout40 = 0;
    double gout41 = 0;
    double gout42 = 0;
    double gout43 = 0;
    double gout44 = 0;
    double gout45 = 0;
    double gout46 = 0;
    double gout47 = 0;
    double gout48 = 0;
    double gout49 = 0;
    double gout50 = 0;
    double gout51 = 0;
    double gout52 = 0;
    double gout53 = 0;
    double gout54 = 0;
    double gout55 = 0;
    double gout56 = 0;
    double gout57 = 0;
    double gout58 = 0;
    double gout59 = 0;
    double gout60 = 0;
    double gout61 = 0;
    double gout62 = 0;
    double gout63 = 0;
    double gout64 = 0;
    double gout65 = 0;
    double gout66 = 0;
    double gout67 = 0;
    double gout68 = 0;
    double gout69 = 0;
    double gout70 = 0;
    double gout71 = 0;
    double gout72 = 0;
    double gout73 = 0;
    double gout74 = 0;
    double gout75 = 0;
    double gout76 = 0;
    double gout77 = 0;
    double gout78 = 0;
    double gout79 = 0;
    double gout80 = 0;
    double gout81 = 0;
    double gout82 = 0;
    double gout83 = 0;
    double gout84 = 0;
    double gout85 = 0;
    double gout86 = 0;
    double gout87 = 0;
    double gout88 = 0;
    double gout89 = 0;
    double gout90 = 0;
    double gout91 = 0;
    double gout92 = 0;
    double gout93 = 0;
    double gout94 = 0;
    double gout95 = 0;
    double gout96 = 0;
    double gout97 = 0;
    double gout98 = 0;
    double gout99 = 0;
    double gout100 = 0;
    double gout101 = 0;
    double gout102 = 0;
    double gout103 = 0;
    double gout104 = 0;
    double gout105 = 0;
    double gout106 = 0;
    double gout107 = 0;
    double gout108 = 0;
    double gout109 = 0;
    double gout110 = 0;
    double gout111 = 0;
    double gout112 = 0;
    double gout113 = 0;
    double gout114 = 0;
    double gout115 = 0;
    double gout116 = 0;
    double gout117 = 0;
    double gout118 = 0;
    double gout119 = 0;
    double gout120 = 0;
    double gout121 = 0;
    double gout122 = 0;
    double gout123 = 0;
    double gout124 = 0;
    double gout125 = 0;
    double gout126 = 0;
    double gout127 = 0;
    double gout128 = 0;
    double gout129 = 0;
    double gout130 = 0;
    double gout131 = 0;
    double gout132 = 0;
    double gout133 = 0;
    double gout134 = 0;
    double gout135 = 0;
    double gout136 = 0;
    double gout137 = 0;
    double gout138 = 0;
    double gout139 = 0;
    double gout140 = 0;
    double gout141 = 0;
    double gout142 = 0;
    double gout143 = 0;
    double gout144 = 0;
    double gout145 = 0;
    double gout146 = 0;
    double gout147 = 0;
    double gout148 = 0;
    double gout149 = 0;
    double gout150 = 0;
    double gout151 = 0;
    double gout152 = 0;
    double gout153 = 0;
    double gout154 = 0;
    double gout155 = 0;
    double gout156 = 0;
    double gout157 = 0;
    double gout158 = 0;
    double gout159 = 0;
    double gout160 = 0;
    double gout161 = 0;
    double gout162 = 0;
    double gout163 = 0;
    double gout164 = 0;
    double gout165 = 0;
    double gout166 = 0;
    double gout167 = 0;
    double gout168 = 0;
    double gout169 = 0;
    double gout170 = 0;
    double gout171 = 0;
    double gout172 = 0;
    double gout173 = 0;
    double gout174 = 0;
    double gout175 = 0;
    double gout176 = 0;
    double gout177 = 0;
    double gout178 = 0;
    double gout179 = 0;
    double gout180 = 0;
    double gout181 = 0;
    double gout182 = 0;
    double gout183 = 0;
    double gout184 = 0;
    double gout185 = 0;
    double gout186 = 0;
    double gout187 = 0;
    double gout188 = 0;
    double gout189 = 0;
    double gout190 = 0;
    double gout191 = 0;
    double gout192 = 0;
    double gout193 = 0;
    double gout194 = 0;
    double gout195 = 0;
    double gout196 = 0;
    double gout197 = 0;
    double gout198 = 0;
    double gout199 = 0;
    double gout200 = 0;
    double gout201 = 0;
    double gout202 = 0;
    double gout203 = 0;
    double gout204 = 0;
    double gout205 = 0;
    double gout206 = 0;
    double gout207 = 0;
    double gout208 = 0;
    double gout209 = 0;
    double gout210 = 0;
    double gout211 = 0;
    double gout212 = 0;
    double gout213 = 0;
    double gout214 = 0;
    double gout215 = 0;
    double gout216 = 0;
    double gout217 = 0;
    double gout218 = 0;
    double gout219 = 0;
    double gout220 = 0;
    double gout221 = 0;
    double gout222 = 0;
    double gout223 = 0;
    double gout224 = 0;
    double gout225 = 0;
    double gout226 = 0;
    double gout227 = 0;
    double gout228 = 0;
    double gout229 = 0;
    double gout230 = 0;
    double gout231 = 0;
    double gout232 = 0;
    double gout233 = 0;
    double gout234 = 0;
    double gout235 = 0;
    double gout236 = 0;
    double gout237 = 0;
    double gout238 = 0;
    double gout239 = 0;
    double gout240 = 0;
    double gout241 = 0;
    double gout242 = 0;
    double gout243 = 0;
    double gout244 = 0;
    double gout245 = 0;
    double gout246 = 0;
    double gout247 = 0;
    double gout248 = 0;
    double gout249 = 0;
    double gout250 = 0;
    double gout251 = 0;
    double gout252 = 0;
    double gout253 = 0;
    double gout254 = 0;
    double gout255 = 0;
    double gout256 = 0;
    double gout257 = 0;
    double gout258 = 0;
    double gout259 = 0;
    double gout260 = 0;
    double gout261 = 0;
    double gout262 = 0;
    double gout263 = 0;
    double gout264 = 0;
    double gout265 = 0;
    double gout266 = 0;
    double gout267 = 0;
    double gout268 = 0;
    double gout269 = 0;
    double gout270 = 0;
    double gout271 = 0;
    double gout272 = 0;
    double gout273 = 0;
    double gout274 = 0;
    double gout275 = 0;
    double gout276 = 0;
    double gout277 = 0;
    double gout278 = 0;
    double gout279 = 0;
    double gout280 = 0;
    double gout281 = 0;
    double gout282 = 0;
    double gout283 = 0;
    double gout284 = 0;
    double gout285 = 0;
    double gout286 = 0;
    double gout287 = 0;
    double gout288 = 0;
    double gout289 = 0;
    double gout290 = 0;
    double gout291 = 0;
    double gout292 = 0;
    double gout293 = 0;
    double gout294 = 0;
    double gout295 = 0;
    double gout296 = 0;
    double gout297 = 0;
    double gout298 = 0;
    double gout299 = 0;
    double gout300 = 0;
    double gout301 = 0;
    double gout302 = 0;
    double gout303 = 0;
    double gout304 = 0;
    double gout305 = 0;
    double gout306 = 0;
    double gout307 = 0;
    double gout308 = 0;
    double gout309 = 0;
    double gout310 = 0;
    double gout311 = 0;
    double gout312 = 0;
    double gout313 = 0;
    double gout314 = 0;
    double gout315 = 0;
    double gout316 = 0;
    double gout317 = 0;
    double gout318 = 0;
    double gout319 = 0;
    double gout320 = 0;
    double gout321 = 0;
    double gout322 = 0;
    double gout323 = 0;

    double xi = bas_x[ish];
    double yi = bas_y[ish];
    double zi = bas_z[ish];
    double ABx = xi - bas_x[jsh];
    double ABy = yi - bas_y[jsh];
    double ABz = zi - bas_z[jsh];
    double xk = bas_x[ksh];
    double yk = bas_y[ksh];
    double zk = bas_z[ksh];

    prim_ij0 = prim_ij;
    prim_ij1 = prim_ij + nprim_ij;
    prim_kl0 = prim_kl;
    prim_kl1 = prim_kl + nprim_kl;
    double rw[6];
    int irys;
    for (ij = prim_ij0; ij < prim_ij1; ++ij) {
        double alpha = i_exponent[ij];
        double beta = j_exponent[ij];
        double aij = a12[ij];
        double eij = e12[ij];
        double xij = x12[ij];
        double yij = y12[ij];
        double zij = z12[ij];
    for (kl = prim_kl0; kl < prim_kl1; ++kl) {
        double akl = a12[kl];
        double ekl = e12[kl];
        double xkl = x12[kl];
        double ykl = y12[kl];
        double zkl = z12[kl];
        double xijxkl = xij - xkl;
        double yijykl = yij - ykl;
        double zijzkl = zij - zkl;
        double aijkl = aij + akl;
        double a1 = aij * akl;
        double a0 = a1 / aijkl;
        double theta = omega > 0.0 ? omega * omega / (omega * omega + a0) : 1.0; 
        a0 *= theta;
        double x = a0 * (xijxkl * xijxkl + yijykl * yijykl + zijzkl * zijzkl);
        double fac = norm * eij * ekl * sqrt(a0 / (a1 * a1 * a1));
        //double fac = norm * eij * ekl / (sqrt(aijkl) * a1);

        GINTrys_root<3>(x, rw);
        GINTscale_u<3>(rw, theta);
      for (irys = 0; irys < 3; ++irys) {
            double weight0 = rw[irys+3] * fac;
            double root0 = rw[irys];
            double u2 = a0 * root0;
            double tmp4 = .5 / (u2 * aijkl + a1);
            double B00 = u2 * tmp4;
            double tmp1 = 2 * B00;
            double B10 = B00 + tmp4 * akl;
            double tmp2 = tmp1 * akl;
            double C00x = xij - xi - tmp2 * xijxkl;
            double C00y = yij - yi - tmp2 * yijykl;
            double C00z = zij - zi - tmp2 * zijzkl;
            double B01 = B00 + tmp4 * aij;
            double tmp3 = tmp1 * aij;
            double D00x = xkl - xk + tmp3 * xijxkl;
            double D00y = ykl - yk + tmp3 * yijykl;
            double D00z = zkl - zk + tmp3 * zijzkl;

            double g0 = B10+C00x*C00x;
            double g1 = C00x*D00x;
            double g2 = B00+g1;
            double g3 = 2*B00*C00x;
            double g4 = g0*D00x;
            double g5 = g3+g4;
            double g6 = B01+D00x*D00x;
            double g7 = 2*B00*D00x;
            double g8 = C00x*g6;
            double g9 = g7+g8;
            double g10 = 2*B00*B00;
            double g11 = 4*B00*C00x*D00x;
            double g12 = g0*g6;
            double g13 = g10+g11+g12;
            double g14 = ABx+C00x;
            double g15 = C00x*g14;
            double g16 = B10+g15;
            double g17 = 3*B10*C00x;
            double g18 = ABx*g0;
            double g19 = g17+C00x*C00x*C00x+g18;
            double g21 = B00+(g14*D00x);
            double g23 = ABx+(2*C00x);
            double g26 = (B00*g23)+(g16*D00x);
            double g27 = 3*B10;
            double g35 = (B00*(g27+(C00x*((2*ABx)+(3*C00x)))))+(g19*D00x);
            double g37 = g7+(g14*g6);
            double g40 = g10+(2*B00*g23*D00x)+(g16*g6);
            double g41 = 6*B00*B00*C00x;
            double g42 = 6*B00*g0*D00x;
            double g43 = g27+C00x*C00x;
            double g44 = C00x*g43*g6;
            double g46 = g41+g42+g44+(ABx*g13);
            double g47 = B10+g14*g14;
            double g50 = (ABx*ABx*C00x)+g17+C00x*C00x*C00x+(2*ABx*g0);
            double g53 = (2*B00*g14)+(g47*D00x);
            double g59 = (4*ABx*B00*C00x)+(3*B00*g0)+(2*ABx*g0*D00x)+(C00x*g43*D00x)+(ABx*ABx*g2);
            double g62 = g10+(4*B00*g14*D00x)+(g47*g6);
            double g65 = g41+g42+g44+(ABx*ABx*g9)+(2*ABx*g13);
            double g66 = B10+C00y*C00y;
            double g68 = B00+(C00y*D00y);
            double g71 = (2*B00*C00y)+(g66*D00y);
            double g72 = B01+D00y*D00y;
            double g73 = 2*B00*D00y;
            double g75 = g73+(C00y*g72);
            double g78 = g10+(4*B00*C00y*D00y)+(g66*g72);
            double g79 = ABy+C00y;
            double g81 = B10+(C00y*g79);
            double g82 = 3*B10*C00y;
            double g84 = g82+C00y*C00y*C00y+(ABy*g66);
            double g86 = B00+(g79*D00y);
            double g88 = ABy+(2*C00y);
            double g91 = (B00*g88)+(g81*D00y);
            double g99 = (B00*(g27+(C00y*((2*ABy)+(3*C00y)))))+(g84*D00y);
            double g101 = g73+(g79*g72);
            double g104 = g10+(2*B00*g88*D00y)+(g81*g72);
            double g105 = 6*B00*B00*C00y;
            double g106 = 6*B00*g66*D00y;
            double g107 = g27+C00y*C00y;
            double g108 = C00y*g107*g72;
            double g110 = g105+g106+g108+(ABy*g78);
            double g111 = B10+g79*g79;
            double g114 = (ABy*ABy*C00y)+g82+C00y*C00y*C00y+(2*ABy*g66);
            double g117 = (2*B00*g79)+(g111*D00y);
            double g123 = (4*ABy*B00*C00y)+(3*B00*g66)+(2*ABy*g66*D00y)+(C00y*g107*D00y)+(ABy*ABy*g68);
            double g126 = g10+(4*B00*g79*D00y)+(g111*g72);
            double g129 = g105+g106+g108+(ABy*ABy*g75)+(2*ABy*g78);
            double g130 = B10+C00z*C00z;
            double g132 = B00+(C00z*D00z);
            double g135 = (2*B00*C00z)+(g130*D00z);
            double g136 = B01+D00z*D00z;
            double g137 = 2*B00*D00z;
            double g139 = g137+(C00z*g136);
            double g142 = g10+(4*B00*C00z*D00z)+(g130*g136);
            double g143 = ABz+C00z;
            double g145 = B10+(C00z*g143);
            double g146 = 3*B10*C00z;
            double g148 = g146+C00z*C00z*C00z+(ABz*g130);
            double g150 = B00+(g143*D00z);
            double g152 = ABz+(2*C00z);
            double g155 = (B00*g152)+(g145*D00z);
            double g163 = (B00*(g27+(C00z*((2*ABz)+(3*C00z)))))+(g148*D00z);
            double g165 = g137+(g143*g136);
            double g168 = g10+(2*B00*g152*D00z)+(g145*g136);
            double g169 = 6*B00*B00*C00z;
            double g170 = 6*B00*g130*D00z;
            double g171 = g27+C00z*C00z;
            double g172 = C00z*g171*g136;
            double g174 = g169+g170+g172+(ABz*g142);
            double g175 = B10+g143*g143;
            double g178 = (ABz*ABz*C00z)+g146+C00z*C00z*C00z+(2*ABz*g130);
            double g181 = (2*B00*g143)+(g175*D00z);
            double g187 = (4*ABz*B00*C00z)+(3*B00*g130)+(2*ABz*g130*D00z)+(C00z*g171*D00z)+(ABz*ABz*g132);
            double g190 = g10+(4*B00*g143*D00z)+(g175*g136);
            double g193 = g169+g170+g172+(ABz*ABz*g139)+(2*ABz*g142);

            gout0 += (-g37 + 2*alpha*g46) * weight0;
            gout1 += (-g21 + 2*alpha*g35) * (D00y) * weight0;
            gout2 += (-g21 + 2*alpha*g35) * (D00z) * weight0;
            gout3 += (-g14 + 2*alpha*g19) * (g72) * weight0;
            gout4 += (-g14 + 2*alpha*g19) * (D00y) * (D00z) * weight0;
            gout5 += (-g14 + 2*alpha*g19) * (g136) * weight0;
            gout6 += (-g6 + 2*alpha*g13) * (g79) * weight0;
            gout7 += (-D00x + 2*alpha*g5) * (g86) * weight0;
            gout8 += (-D00x + 2*alpha*g5) * (g79) * (D00z) * weight0;
            gout9 += (-1 + 2*alpha*g0) * (g101) * weight0;
            gout10 += (-1 + 2*alpha*g0) * (g86) * (D00z) * weight0;
            gout11 += (-1 + 2*alpha*g0) * (g79) * (g136) * weight0;
            gout12 += (-g6 + 2*alpha*g13) * (g143) * weight0;
            gout13 += (-D00x + 2*alpha*g5) * (D00y) * (g143) * weight0;
            gout14 += (-D00x + 2*alpha*g5) * (g150) * weight0;
            gout15 += (-1 + 2*alpha*g0) * (g72) * (g143) * weight0;
            gout16 += (-1 + 2*alpha*g0) * (D00y) * (g150) * weight0;
            gout17 += (-1 + 2*alpha*g0) * (g165) * weight0;
            gout18 += (2*alpha*g40) * (C00y) * weight0;
            gout19 += (2*alpha*g26) * (g68) * weight0;
            gout20 += (2*alpha*g26) * (C00y) * (D00z) * weight0;
            gout21 += (2*alpha*g16) * (g75) * weight0;
            gout22 += (2*alpha*g16) * (g68) * (D00z) * weight0;
            gout23 += (2*alpha*g16) * (C00y) * (g136) * weight0;
            gout24 += (2*alpha*g9) * (g81) * weight0;
            gout25 += (2*alpha*g2) * (g91) * weight0;
            gout26 += (2*alpha*g2) * (g81) * (D00z) * weight0;
            gout27 += (2*alpha*C00x) * (g104) * weight0;
            gout28 += (2*alpha*C00x) * (g91) * (D00z) * weight0;
            gout29 += (2*alpha*C00x) * (g81) * (g136) * weight0;
            gout30 += (2*alpha*g9) * (C00y) * (g143) * weight0;
            gout31 += (2*alpha*g2) * (g68) * (g143) * weight0;
            gout32 += (2*alpha*g2) * (C00y) * (g150) * weight0;
            gout33 += (2*alpha*C00x) * (g75) * (g143) * weight0;
            gout34 += (2*alpha*C00x) * (g68) * (g150) * weight0;
            gout35 += (2*alpha*C00x) * (C00y) * (g165) * weight0;
            gout36 += (2*alpha*g40) * (C00z) * weight0;
            gout37 += (2*alpha*g26) * (D00y) * (C00z) * weight0;
            gout38 += (2*alpha*g26) * (g132) * weight0;
            gout39 += (2*alpha*g16) * (g72) * (C00z) * weight0;
            gout40 += (2*alpha*g16) * (D00y) * (g132) * weight0;
            gout41 += (2*alpha*g16) * (g139) * weight0;
            gout42 += (2*alpha*g9) * (g79) * (C00z) * weight0;
            gout43 += (2*alpha*g2) * (g86) * (C00z) * weight0;
            gout44 += (2*alpha*g2) * (g79) * (g132) * weight0;
            gout45 += (2*alpha*C00x) * (g101) * (C00z) * weight0;
            gout46 += (2*alpha*C00x) * (g86) * (g132) * weight0;
            gout47 += (2*alpha*C00x) * (g79) * (g139) * weight0;
            gout48 += (2*alpha*g9) * (g145) * weight0;
            gout49 += (2*alpha*g2) * (D00y) * (g145) * weight0;
            gout50 += (2*alpha*g2) * (g155) * weight0;
            gout51 += (2*alpha*C00x) * (g72) * (g145) * weight0;
            gout52 += (2*alpha*C00x) * (D00y) * (g155) * weight0;
            gout53 += (2*alpha*C00x) * (g168) * weight0;
            gout54 += (g40) * (2*alpha*C00y) * weight0;
            gout55 += (g26) * (2*alpha*g68) * weight0;
            gout56 += (g26) * (2*alpha*C00y) * (D00z) * weight0;
            gout57 += (g16) * (2*alpha*g75) * weight0;
            gout58 += (g16) * (2*alpha*g68) * (D00z) * weight0;
            gout59 += (g16) * (2*alpha*C00y) * (g136) * weight0;
            gout60 += (g9) * (2*alpha*g81) * weight0;
            gout61 += (g2) * (2*alpha*g91) * weight0;
            gout62 += (g2) * (2*alpha*g81) * (D00z) * weight0;
            gout63 += (C00x) * (2*alpha*g104) * weight0;
            gout64 += (C00x) * (2*alpha*g91) * (D00z) * weight0;
            gout65 += (C00x) * (2*alpha*g81) * (g136) * weight0;
            gout66 += (g9) * (2*alpha*C00y) * (g143) * weight0;
            gout67 += (g2) * (2*alpha*g68) * (g143) * weight0;
            gout68 += (g2) * (2*alpha*C00y) * (g150) * weight0;
            gout69 += (C00x) * (2*alpha*g75) * (g143) * weight0;
            gout70 += (C00x) * (2*alpha*g68) * (g150) * weight0;
            gout71 += (C00x) * (2*alpha*C00y) * (g165) * weight0;
            gout72 += (g37) * (-1 + 2*alpha*g66) * weight0;
            gout73 += (g21) * (-D00y + 2*alpha*g71) * weight0;
            gout74 += (g21) * (-1 + 2*alpha*g66) * (D00z) * weight0;
            gout75 += (g14) * (-g72 + 2*alpha*g78) * weight0;
            gout76 += (g14) * (-D00y + 2*alpha*g71) * (D00z) * weight0;
            gout77 += (g14) * (-1 + 2*alpha*g66) * (g136) * weight0;
            gout78 += (g6) * (-g79 + 2*alpha*g84) * weight0;
            gout79 += (D00x) * (-g86 + 2*alpha*g99) * weight0;
            gout80 += (D00x) * (-g79 + 2*alpha*g84) * (D00z) * weight0;
            gout81 += (-g101 + 2*alpha*g110) * weight0;
            gout82 += (-g86 + 2*alpha*g99) * (D00z) * weight0;
            gout83 += (-g79 + 2*alpha*g84) * (g136) * weight0;
            gout84 += (g6) * (-1 + 2*alpha*g66) * (g143) * weight0;
            gout85 += (D00x) * (-D00y + 2*alpha*g71) * (g143) * weight0;
            gout86 += (D00x) * (-1 + 2*alpha*g66) * (g150) * weight0;
            gout87 += (-g72 + 2*alpha*g78) * (g143) * weight0;
            gout88 += (-D00y + 2*alpha*g71) * (g150) * weight0;
            gout89 += (-1 + 2*alpha*g66) * (g165) * weight0;
            gout90 += (g37) * (2*alpha*C00y) * (C00z) * weight0;
            gout91 += (g21) * (2*alpha*g68) * (C00z) * weight0;
            gout92 += (g21) * (2*alpha*C00y) * (g132) * weight0;
            gout93 += (g14) * (2*alpha*g75) * (C00z) * weight0;
            gout94 += (g14) * (2*alpha*g68) * (g132) * weight0;
            gout95 += (g14) * (2*alpha*C00y) * (g139) * weight0;
            gout96 += (g6) * (2*alpha*g81) * (C00z) * weight0;
            gout97 += (D00x) * (2*alpha*g91) * (C00z) * weight0;
            gout98 += (D00x) * (2*alpha*g81) * (g132) * weight0;
            gout99 += (2*alpha*g104) * (C00z) * weight0;
            gout100 += (2*alpha*g91) * (g132) * weight0;
            gout101 += (2*alpha*g81) * (g139) * weight0;
            gout102 += (g6) * (2*alpha*C00y) * (g145) * weight0;
            gout103 += (D00x) * (2*alpha*g68) * (g145) * weight0;
            gout104 += (D00x) * (2*alpha*C00y) * (g155) * weight0;
            gout105 += (2*alpha*g75) * (g145) * weight0;
            gout106 += (2*alpha*g68) * (g155) * weight0;
            gout107 += (2*alpha*C00y) * (g168) * weight0;
            gout108 += (g40) * (2*alpha*C00z) * weight0;
            gout109 += (g26) * (D00y) * (2*alpha*C00z) * weight0;
            gout110 += (g26) * (2*alpha*g132) * weight0;
            gout111 += (g16) * (g72) * (2*alpha*C00z) * weight0;
            gout112 += (g16) * (D00y) * (2*alpha*g132) * weight0;
            gout113 += (g16) * (2*alpha*g139) * weight0;
            gout114 += (g9) * (g79) * (2*alpha*C00z) * weight0;
            gout115 += (g2) * (g86) * (2*alpha*C00z) * weight0;
            gout116 += (g2) * (g79) * (2*alpha*g132) * weight0;
            gout117 += (C00x) * (g101) * (2*alpha*C00z) * weight0;
            gout118 += (C00x) * (g86) * (2*alpha*g132) * weight0;
            gout119 += (C00x) * (g79) * (2*alpha*g139) * weight0;
            gout120 += (g9) * (2*alpha*g145) * weight0;
            gout121 += (g2) * (D00y) * (2*alpha*g145) * weight0;
            gout122 += (g2) * (2*alpha*g155) * weight0;
            gout123 += (C00x) * (g72) * (2*alpha*g145) * weight0;
            gout124 += (C00x) * (D00y) * (2*alpha*g155) * weight0;
            gout125 += (C00x) * (2*alpha*g168) * weight0;
            gout126 += (g37) * (C00y) * (2*alpha*C00z) * weight0;
            gout127 += (g21) * (g68) * (2*alpha*C00z) * weight0;
            gout128 += (g21) * (C00y) * (2*alpha*g132) * weight0;
            gout129 += (g14) * (g75) * (2*alpha*C00z) * weight0;
            gout130 += (g14) * (g68) * (2*alpha*g132) * weight0;
            gout131 += (g14) * (C00y) * (2*alpha*g139) * weight0;
            gout132 += (g6) * (g81) * (2*alpha*C00z) * weight0;
            gout133 += (D00x) * (g91) * (2*alpha*C00z) * weight0;
            gout134 += (D00x) * (g81) * (2*alpha*g132) * weight0;
            gout135 += (g104) * (2*alpha*C00z) * weight0;
            gout136 += (g91) * (2*alpha*g132) * weight0;
            gout137 += (g81) * (2*alpha*g139) * weight0;
            gout138 += (g6) * (C00y) * (2*alpha*g145) * weight0;
            gout139 += (D00x) * (g68) * (2*alpha*g145) * weight0;
            gout140 += (D00x) * (C00y) * (2*alpha*g155) * weight0;
            gout141 += (g75) * (2*alpha*g145) * weight0;
            gout142 += (g68) * (2*alpha*g155) * weight0;
            gout143 += (C00y) * (2*alpha*g168) * weight0;
            gout144 += (g37) * (-1 + 2*alpha*g130) * weight0;
            gout145 += (g21) * (D00y) * (-1 + 2*alpha*g130) * weight0;
            gout146 += (g21) * (-D00z + 2*alpha*g135) * weight0;
            gout147 += (g14) * (g72) * (-1 + 2*alpha*g130) * weight0;
            gout148 += (g14) * (D00y) * (-D00z + 2*alpha*g135) * weight0;
            gout149 += (g14) * (-g136 + 2*alpha*g142) * weight0;
            gout150 += (g6) * (g79) * (-1 + 2*alpha*g130) * weight0;
            gout151 += (D00x) * (g86) * (-1 + 2*alpha*g130) * weight0;
            gout152 += (D00x) * (g79) * (-D00z + 2*alpha*g135) * weight0;
            gout153 += (g101) * (-1 + 2*alpha*g130) * weight0;
            gout154 += (g86) * (-D00z + 2*alpha*g135) * weight0;
            gout155 += (g79) * (-g136 + 2*alpha*g142) * weight0;
            gout156 += (g6) * (-g143 + 2*alpha*g148) * weight0;
            gout157 += (D00x) * (D00y) * (-g143 + 2*alpha*g148) * weight0;
            gout158 += (D00x) * (-g150 + 2*alpha*g163) * weight0;
            gout159 += (g72) * (-g143 + 2*alpha*g148) * weight0;
            gout160 += (D00y) * (-g150 + 2*alpha*g163) * weight0;
            gout161 += (-g165 + 2*alpha*g174) * weight0;
            gout162 += (-g9 + 2*beta*g65) * weight0;
            gout163 += (-g2 + 2*beta*g59) * (D00y) * weight0;
            gout164 += (-g2 + 2*beta*g59) * (D00z) * weight0;
            gout165 += (-C00x + 2*beta*g50) * (g72) * weight0;
            gout166 += (-C00x + 2*beta*g50) * (D00y) * (D00z) * weight0;
            gout167 += (-C00x + 2*beta*g50) * (g136) * weight0;
            gout168 += (2*beta*g40) * (g79) * weight0;
            gout169 += (2*beta*g26) * (g86) * weight0;
            gout170 += (2*beta*g26) * (g79) * (D00z) * weight0;
            gout171 += (2*beta*g16) * (g101) * weight0;
            gout172 += (2*beta*g16) * (g86) * (D00z) * weight0;
            gout173 += (2*beta*g16) * (g79) * (g136) * weight0;
            gout174 += (2*beta*g40) * (g143) * weight0;
            gout175 += (2*beta*g26) * (D00y) * (g143) * weight0;
            gout176 += (2*beta*g26) * (g150) * weight0;
            gout177 += (2*beta*g16) * (g72) * (g143) * weight0;
            gout178 += (2*beta*g16) * (D00y) * (g150) * weight0;
            gout179 += (2*beta*g16) * (g165) * weight0;
            gout180 += (-g6 + 2*beta*g62) * (C00y) * weight0;
            gout181 += (-D00x + 2*beta*g53) * (g68) * weight0;
            gout182 += (-D00x + 2*beta*g53) * (C00y) * (D00z) * weight0;
            gout183 += (-1 + 2*beta*g47) * (g75) * weight0;
            gout184 += (-1 + 2*beta*g47) * (g68) * (D00z) * weight0;
            gout185 += (-1 + 2*beta*g47) * (C00y) * (g136) * weight0;
            gout186 += (2*beta*g37) * (g81) * weight0;
            gout187 += (2*beta*g21) * (g91) * weight0;
            gout188 += (2*beta*g21) * (g81) * (D00z) * weight0;
            gout189 += (2*beta*g14) * (g104) * weight0;
            gout190 += (2*beta*g14) * (g91) * (D00z) * weight0;
            gout191 += (2*beta*g14) * (g81) * (g136) * weight0;
            gout192 += (2*beta*g37) * (C00y) * (g143) * weight0;
            gout193 += (2*beta*g21) * (g68) * (g143) * weight0;
            gout194 += (2*beta*g21) * (C00y) * (g150) * weight0;
            gout195 += (2*beta*g14) * (g75) * (g143) * weight0;
            gout196 += (2*beta*g14) * (g68) * (g150) * weight0;
            gout197 += (2*beta*g14) * (C00y) * (g165) * weight0;
            gout198 += (-g6 + 2*beta*g62) * (C00z) * weight0;
            gout199 += (-D00x + 2*beta*g53) * (D00y) * (C00z) * weight0;
            gout200 += (-D00x + 2*beta*g53) * (g132) * weight0;
            gout201 += (-1 + 2*beta*g47) * (g72) * (C00z) * weight0;
            gout202 += (-1 + 2*beta*g47) * (D00y) * (g132) * weight0;
            gout203 += (-1 + 2*beta*g47) * (g139) * weight0;
            gout204 += (2*beta*g37) * (g79) * (C00z) * weight0;
            gout205 += (2*beta*g21) * (g86) * (C00z) * weight0;
            gout206 += (2*beta*g21) * (g79) * (g132) * weight0;
            gout207 += (2*beta*g14) * (g101) * (C00z) * weight0;
            gout208 += (2*beta*g14) * (g86) * (g132) * weight0;
            gout209 += (2*beta*g14) * (g79) * (g139) * weight0;
            gout210 += (2*beta*g37) * (g145) * weight0;
            gout211 += (2*beta*g21) * (D00y) * (g145) * weight0;
            gout212 += (2*beta*g21) * (g155) * weight0;
            gout213 += (2*beta*g14) * (g72) * (g145) * weight0;
            gout214 += (2*beta*g14) * (D00y) * (g155) * weight0;
            gout215 += (2*beta*g14) * (g168) * weight0;
            gout216 += (g40) * (2*beta*g79) * weight0;
            gout217 += (g26) * (2*beta*g86) * weight0;
            gout218 += (g26) * (2*beta*g79) * (D00z) * weight0;
            gout219 += (g16) * (2*beta*g101) * weight0;
            gout220 += (g16) * (2*beta*g86) * (D00z) * weight0;
            gout221 += (g16) * (2*beta*g79) * (g136) * weight0;
            gout222 += (g9) * (-1 + 2*beta*g111) * weight0;
            gout223 += (g2) * (-D00y + 2*beta*g117) * weight0;
            gout224 += (g2) * (-1 + 2*beta*g111) * (D00z) * weight0;
            gout225 += (C00x) * (-g72 + 2*beta*g126) * weight0;
            gout226 += (C00x) * (-D00y + 2*beta*g117) * (D00z) * weight0;
            gout227 += (C00x) * (-1 + 2*beta*g111) * (g136) * weight0;
            gout228 += (g9) * (2*beta*g79) * (g143) * weight0;
            gout229 += (g2) * (2*beta*g86) * (g143) * weight0;
            gout230 += (g2) * (2*beta*g79) * (g150) * weight0;
            gout231 += (C00x) * (2*beta*g101) * (g143) * weight0;
            gout232 += (C00x) * (2*beta*g86) * (g150) * weight0;
            gout233 += (C00x) * (2*beta*g79) * (g165) * weight0;
            gout234 += (g37) * (2*beta*g81) * weight0;
            gout235 += (g21) * (2*beta*g91) * weight0;
            gout236 += (g21) * (2*beta*g81) * (D00z) * weight0;
            gout237 += (g14) * (2*beta*g104) * weight0;
            gout238 += (g14) * (2*beta*g91) * (D00z) * weight0;
            gout239 += (g14) * (2*beta*g81) * (g136) * weight0;
            gout240 += (g6) * (-C00y + 2*beta*g114) * weight0;
            gout241 += (D00x) * (-g68 + 2*beta*g123) * weight0;
            gout242 += (D00x) * (-C00y + 2*beta*g114) * (D00z) * weight0;
            gout243 += (-g75 + 2*beta*g129) * weight0;
            gout244 += (-g68 + 2*beta*g123) * (D00z) * weight0;
            gout245 += (-C00y + 2*beta*g114) * (g136) * weight0;
            gout246 += (g6) * (2*beta*g81) * (g143) * weight0;
            gout247 += (D00x) * (2*beta*g91) * (g143) * weight0;
            gout248 += (D00x) * (2*beta*g81) * (g150) * weight0;
            gout249 += (2*beta*g104) * (g143) * weight0;
            gout250 += (2*beta*g91) * (g150) * weight0;
            gout251 += (2*beta*g81) * (g165) * weight0;
            gout252 += (g37) * (2*beta*g79) * (C00z) * weight0;
            gout253 += (g21) * (2*beta*g86) * (C00z) * weight0;
            gout254 += (g21) * (2*beta*g79) * (g132) * weight0;
            gout255 += (g14) * (2*beta*g101) * (C00z) * weight0;
            gout256 += (g14) * (2*beta*g86) * (g132) * weight0;
            gout257 += (g14) * (2*beta*g79) * (g139) * weight0;
            gout258 += (g6) * (-1 + 2*beta*g111) * (C00z) * weight0;
            gout259 += (D00x) * (-D00y + 2*beta*g117) * (C00z) * weight0;
            gout260 += (D00x) * (-1 + 2*beta*g111) * (g132) * weight0;
            gout261 += (-g72 + 2*beta*g126) * (C00z) * weight0;
            gout262 += (-D00y + 2*beta*g117) * (g132) * weight0;
            gout263 += (-1 + 2*beta*g111) * (g139) * weight0;
            gout264 += (g6) * (2*beta*g79) * (g145) * weight0;
            gout265 += (D00x) * (2*beta*g86) * (g145) * weight0;
            gout266 += (D00x) * (2*beta*g79) * (g155) * weight0;
            gout267 += (2*beta*g101) * (g145) * weight0;
            gout268 += (2*beta*g86) * (g155) * weight0;
            gout269 += (2*beta*g79) * (g168) * weight0;
            gout270 += (g40) * (2*beta*g143) * weight0;
            gout271 += (g26) * (D00y) * (2*beta*g143) * weight0;
            gout272 += (g26) * (2*beta*g150) * weight0;
            gout273 += (g16) * (g72) * (2*beta*g143) * weight0;
            gout274 += (g16) * (D00y) * (2*beta*g150) * weight0;
            gout275 += (g16) * (2*beta*g165) * weight0;
            gout276 += (g9) * (g79) * (2*beta*g143) * weight0;
            gout277 += (g2) * (g86) * (2*beta*g143) * weight0;
            gout278 += (g2) * (g79) * (2*beta*g150) * weight0;
            gout279 += (C00x) * (g101) * (2*beta*g143) * weight0;
            gout280 += (C00x) * (g86) * (2*beta*g150) * weight0;
            gout281 += (C00x) * (g79) * (2*beta*g165) * weight0;
            gout282 += (g9) * (-1 + 2*beta*g175) * weight0;
            gout283 += (g2) * (D00y) * (-1 + 2*beta*g175) * weight0;
            gout284 += (g2) * (-D00z + 2*beta*g181) * weight0;
            gout285 += (C00x) * (g72) * (-1 + 2*beta*g175) * weight0;
            gout286 += (C00x) * (D00y) * (-D00z + 2*beta*g181) * weight0;
            gout287 += (C00x) * (-g136 + 2*beta*g190) * weight0;
            gout288 += (g37) * (C00y) * (2*beta*g143) * weight0;
            gout289 += (g21) * (g68) * (2*beta*g143) * weight0;
            gout290 += (g21) * (C00y) * (2*beta*g150) * weight0;
            gout291 += (g14) * (g75) * (2*beta*g143) * weight0;
            gout292 += (g14) * (g68) * (2*beta*g150) * weight0;
            gout293 += (g14) * (C00y) * (2*beta*g165) * weight0;
            gout294 += (g6) * (g81) * (2*beta*g143) * weight0;
            gout295 += (D00x) * (g91) * (2*beta*g143) * weight0;
            gout296 += (D00x) * (g81) * (2*beta*g150) * weight0;
            gout297 += (g104) * (2*beta*g143) * weight0;
            gout298 += (g91) * (2*beta*g150) * weight0;
            gout299 += (g81) * (2*beta*g165) * weight0;
            gout300 += (g6) * (C00y) * (-1 + 2*beta*g175) * weight0;
            gout301 += (D00x) * (g68) * (-1 + 2*beta*g175) * weight0;
            gout302 += (D00x) * (C00y) * (-D00z + 2*beta*g181) * weight0;
            gout303 += (g75) * (-1 + 2*beta*g175) * weight0;
            gout304 += (g68) * (-D00z + 2*beta*g181) * weight0;
            gout305 += (C00y) * (-g136 + 2*beta*g190) * weight0;
            gout306 += (g37) * (2*beta*g145) * weight0;
            gout307 += (g21) * (D00y) * (2*beta*g145) * weight0;
            gout308 += (g21) * (2*beta*g155) * weight0;
            gout309 += (g14) * (g72) * (2*beta*g145) * weight0;
            gout310 += (g14) * (D00y) * (2*beta*g155) * weight0;
            gout311 += (g14) * (2*beta*g168) * weight0;
            gout312 += (g6) * (g79) * (2*beta*g145) * weight0;
            gout313 += (D00x) * (g86) * (2*beta*g145) * weight0;
            gout314 += (D00x) * (g79) * (2*beta*g155) * weight0;
            gout315 += (g101) * (2*beta*g145) * weight0;
            gout316 += (g86) * (2*beta*g155) * weight0;
            gout317 += (g79) * (2*beta*g168) * weight0;
            gout318 += (g6) * (-C00z + 2*beta*g178) * weight0;
            gout319 += (D00x) * (D00y) * (-C00z + 2*beta*g178) * weight0;
            gout320 += (D00x) * (-g132 + 2*beta*g187) * weight0;
            gout321 += (g72) * (-C00z + 2*beta*g178) * weight0;
            gout322 += (D00y) * (-g132 + 2*beta*g187) * weight0;
            gout323 += (-g139 + 2*beta*g193) * weight0;
        }
    } }

    int *ao_loc = c_bpcache.ao_loc;
    int i0 = ao_loc[ish];
    int j0 = ao_loc[jsh];
    int k0 = ao_loc[ksh];
    int l0 = ao_loc[lsh];
    int n_dm = jk.n_dm;
    int nao = jk.nao;
    size_t nao2 = nao * nao;
    double* __restrict__ dm = jk.dm;
    double *vj = jk.vj;
    double *vk = jk.vk;
    double d_0, d_1, d_2, d_3, d_4, d_5, d_6, d_7, d_8, d_9, d_10, d_11, d_12, d_13, d_14, d_15, d_16, d_17;

    for (int i_dm = 0; i_dm < n_dm; ++i_dm) {
        if (vj != NULL) {
            d_0 = dm[(k0+0)+nao*(l0+0)];
            d_1 = dm[(k0+1)+nao*(l0+0)];
            d_2 = dm[(k0+2)+nao*(l0+0)];
            d_3 = dm[(k0+3)+nao*(l0+0)];
            d_4 = dm[(k0+4)+nao*(l0+0)];
            d_5 = dm[(k0+5)+nao*(l0+0)];
            atomicAdd(vj+(i0+0)+nao*(j0+0), gout0*d_0+gout1*d_1+gout2*d_2+gout3*d_3+gout4*d_4+gout5*d_5);
            atomicAdd(vj+(i0+0)+nao*(j0+1), gout6*d_0+gout7*d_1+gout8*d_2+gout9*d_3+gout10*d_4+gout11*d_5);
            atomicAdd(vj+(i0+0)+nao*(j0+2), gout12*d_0+gout13*d_1+gout14*d_2+gout15*d_3+gout16*d_4+gout17*d_5);
            atomicAdd(vj+(i0+1)+nao*(j0+0), gout18*d_0+gout19*d_1+gout20*d_2+gout21*d_3+gout22*d_4+gout23*d_5);
            atomicAdd(vj+(i0+1)+nao*(j0+1), gout24*d_0+gout25*d_1+gout26*d_2+gout27*d_3+gout28*d_4+gout29*d_5);
            atomicAdd(vj+(i0+1)+nao*(j0+2), gout30*d_0+gout31*d_1+gout32*d_2+gout33*d_3+gout34*d_4+gout35*d_5);
            atomicAdd(vj+(i0+2)+nao*(j0+0), gout36*d_0+gout37*d_1+gout38*d_2+gout39*d_3+gout40*d_4+gout41*d_5);
            atomicAdd(vj+(i0+2)+nao*(j0+1), gout42*d_0+gout43*d_1+gout44*d_2+gout45*d_3+gout46*d_4+gout47*d_5);
            atomicAdd(vj+(i0+2)+nao*(j0+2), gout48*d_0+gout49*d_1+gout50*d_2+gout51*d_3+gout52*d_4+gout53*d_5);
            atomicAdd(vj+(i0+0)+nao*(j0+0)+nao2, gout54*d_0+gout55*d_1+gout56*d_2+gout57*d_3+gout58*d_4+gout59*d_5);
            atomicAdd(vj+(i0+0)+nao*(j0+1)+nao2, gout60*d_0+gout61*d_1+gout62*d_2+gout63*d_3+gout64*d_4+gout65*d_5);
            atomicAdd(vj+(i0+0)+nao*(j0+2)+nao2, gout66*d_0+gout67*d_1+gout68*d_2+gout69*d_3+gout70*d_4+gout71*d_5);
            atomicAdd(vj+(i0+1)+nao*(j0+0)+nao2, gout72*d_0+gout73*d_1+gout74*d_2+gout75*d_3+gout76*d_4+gout77*d_5);
            atomicAdd(vj+(i0+1)+nao*(j0+1)+nao2, gout78*d_0+gout79*d_1+gout80*d_2+gout81*d_3+gout82*d_4+gout83*d_5);
            atomicAdd(vj+(i0+1)+nao*(j0+2)+nao2, gout84*d_0+gout85*d_1+gout86*d_2+gout87*d_3+gout88*d_4+gout89*d_5);
            atomicAdd(vj+(i0+2)+nao*(j0+0)+nao2, gout90*d_0+gout91*d_1+gout92*d_2+gout93*d_3+gout94*d_4+gout95*d_5);
            atomicAdd(vj+(i0+2)+nao*(j0+1)+nao2, gout96*d_0+gout97*d_1+gout98*d_2+gout99*d_3+gout100*d_4+gout101*d_5);
            atomicAdd(vj+(i0+2)+nao*(j0+2)+nao2, gout102*d_0+gout103*d_1+gout104*d_2+gout105*d_3+gout106*d_4+gout107*d_5);
            atomicAdd(vj+(i0+0)+nao*(j0+0)+2*nao2, gout108*d_0+gout109*d_1+gout110*d_2+gout111*d_3+gout112*d_4+gout113*d_5);
            atomicAdd(vj+(i0+0)+nao*(j0+1)+2*nao2, gout114*d_0+gout115*d_1+gout116*d_2+gout117*d_3+gout118*d_4+gout119*d_5);
            atomicAdd(vj+(i0+0)+nao*(j0+2)+2*nao2, gout120*d_0+gout121*d_1+gout122*d_2+gout123*d_3+gout124*d_4+gout125*d_5);
            atomicAdd(vj+(i0+1)+nao*(j0+0)+2*nao2, gout126*d_0+gout127*d_1+gout128*d_2+gout129*d_3+gout130*d_4+gout131*d_5);
            atomicAdd(vj+(i0+1)+nao*(j0+1)+2*nao2, gout132*d_0+gout133*d_1+gout134*d_2+gout135*d_3+gout136*d_4+gout137*d_5);
            atomicAdd(vj+(i0+1)+nao*(j0+2)+2*nao2, gout138*d_0+gout139*d_1+gout140*d_2+gout141*d_3+gout142*d_4+gout143*d_5);
            atomicAdd(vj+(i0+2)+nao*(j0+0)+2*nao2, gout144*d_0+gout145*d_1+gout146*d_2+gout147*d_3+gout148*d_4+gout149*d_5);
            atomicAdd(vj+(i0+2)+nao*(j0+1)+2*nao2, gout150*d_0+gout151*d_1+gout152*d_2+gout153*d_3+gout154*d_4+gout155*d_5);
            atomicAdd(vj+(i0+2)+nao*(j0+2)+2*nao2, gout156*d_0+gout157*d_1+gout158*d_2+gout159*d_3+gout160*d_4+gout161*d_5);
            atomicAdd(vj+nao*(i0+0)+(j0+0), gout162*d_0+gout163*d_1+gout164*d_2+gout165*d_3+gout166*d_4+gout167*d_5);
            atomicAdd(vj+nao*(i0+0)+(j0+1), gout168*d_0+gout169*d_1+gout170*d_2+gout171*d_3+gout172*d_4+gout173*d_5);
            atomicAdd(vj+nao*(i0+0)+(j0+2), gout174*d_0+gout175*d_1+gout176*d_2+gout177*d_3+gout178*d_4+gout179*d_5);
            atomicAdd(vj+nao*(i0+1)+(j0+0), gout180*d_0+gout181*d_1+gout182*d_2+gout183*d_3+gout184*d_4+gout185*d_5);
            atomicAdd(vj+nao*(i0+1)+(j0+1), gout186*d_0+gout187*d_1+gout188*d_2+gout189*d_3+gout190*d_4+gout191*d_5);
            atomicAdd(vj+nao*(i0+1)+(j0+2), gout192*d_0+gout193*d_1+gout194*d_2+gout195*d_3+gout196*d_4+gout197*d_5);
            atomicAdd(vj+nao*(i0+2)+(j0+0), gout198*d_0+gout199*d_1+gout200*d_2+gout201*d_3+gout202*d_4+gout203*d_5);
            atomicAdd(vj+nao*(i0+2)+(j0+1), gout204*d_0+gout205*d_1+gout206*d_2+gout207*d_3+gout208*d_4+gout209*d_5);
            atomicAdd(vj+nao*(i0+2)+(j0+2), gout210*d_0+gout211*d_1+gout212*d_2+gout213*d_3+gout214*d_4+gout215*d_5);
            atomicAdd(vj+nao*(i0+0)+(j0+0)+nao2, gout216*d_0+gout217*d_1+gout218*d_2+gout219*d_3+gout220*d_4+gout221*d_5);
            atomicAdd(vj+nao*(i0+0)+(j0+1)+nao2, gout222*d_0+gout223*d_1+gout224*d_2+gout225*d_3+gout226*d_4+gout227*d_5);
            atomicAdd(vj+nao*(i0+0)+(j0+2)+nao2, gout228*d_0+gout229*d_1+gout230*d_2+gout231*d_3+gout232*d_4+gout233*d_5);
            atomicAdd(vj+nao*(i0+1)+(j0+0)+nao2, gout234*d_0+gout235*d_1+gout236*d_2+gout237*d_3+gout238*d_4+gout239*d_5);
            atomicAdd(vj+nao*(i0+1)+(j0+1)+nao2, gout240*d_0+gout241*d_1+gout242*d_2+gout243*d_3+gout244*d_4+gout245*d_5);
            atomicAdd(vj+nao*(i0+1)+(j0+2)+nao2, gout246*d_0+gout247*d_1+gout248*d_2+gout249*d_3+gout250*d_4+gout251*d_5);
            atomicAdd(vj+nao*(i0+2)+(j0+0)+nao2, gout252*d_0+gout253*d_1+gout254*d_2+gout255*d_3+gout256*d_4+gout257*d_5);
            atomicAdd(vj+nao*(i0+2)+(j0+1)+nao2, gout258*d_0+gout259*d_1+gout260*d_2+gout261*d_3+gout262*d_4+gout263*d_5);
            atomicAdd(vj+nao*(i0+2)+(j0+2)+nao2, gout264*d_0+gout265*d_1+gout266*d_2+gout267*d_3+gout268*d_4+gout269*d_5);
            atomicAdd(vj+nao*(i0+0)+(j0+0)+2*nao2, gout270*d_0+gout271*d_1+gout272*d_2+gout273*d_3+gout274*d_4+gout275*d_5);
            atomicAdd(vj+nao*(i0+0)+(j0+1)+2*nao2, gout276*d_0+gout277*d_1+gout278*d_2+gout279*d_3+gout280*d_4+gout281*d_5);
            atomicAdd(vj+nao*(i0+0)+(j0+2)+2*nao2, gout282*d_0+gout283*d_1+gout284*d_2+gout285*d_3+gout286*d_4+gout287*d_5);
            atomicAdd(vj+nao*(i0+1)+(j0+0)+2*nao2, gout288*d_0+gout289*d_1+gout290*d_2+gout291*d_3+gout292*d_4+gout293*d_5);
            atomicAdd(vj+nao*(i0+1)+(j0+1)+2*nao2, gout294*d_0+gout295*d_1+gout296*d_2+gout297*d_3+gout298*d_4+gout299*d_5);
            atomicAdd(vj+nao*(i0+1)+(j0+2)+2*nao2, gout300*d_0+gout301*d_1+gout302*d_2+gout303*d_3+gout304*d_4+gout305*d_5);
            atomicAdd(vj+nao*(i0+2)+(j0+0)+2*nao2, gout306*d_0+gout307*d_1+gout308*d_2+gout309*d_3+gout310*d_4+gout311*d_5);
            atomicAdd(vj+nao*(i0+2)+(j0+1)+2*nao2, gout312*d_0+gout313*d_1+gout314*d_2+gout315*d_3+gout316*d_4+gout317*d_5);
            atomicAdd(vj+nao*(i0+2)+(j0+2)+2*nao2, gout318*d_0+gout319*d_1+gout320*d_2+gout321*d_3+gout322*d_4+gout323*d_5);
            vj += 3*nao2;
        }
        if (vk != NULL) {
            // ijkl, jk -> il
            d_0 = dm[(j0+0)+nao*(k0+0)];
            d_1 = dm[(j0+0)+nao*(k0+1)];
            d_2 = dm[(j0+0)+nao*(k0+2)];
            d_3 = dm[(j0+0)+nao*(k0+3)];
            d_4 = dm[(j0+0)+nao*(k0+4)];
            d_5 = dm[(j0+0)+nao*(k0+5)];
            d_6 = dm[(j0+1)+nao*(k0+0)];
            d_7 = dm[(j0+1)+nao*(k0+1)];
            d_8 = dm[(j0+1)+nao*(k0+2)];
            d_9 = dm[(j0+1)+nao*(k0+3)];
            d_10 = dm[(j0+1)+nao*(k0+4)];
            d_11 = dm[(j0+1)+nao*(k0+5)];
            d_12 = dm[(j0+2)+nao*(k0+0)];
            d_13 = dm[(j0+2)+nao*(k0+1)];
            d_14 = dm[(j0+2)+nao*(k0+2)];
            d_15 = dm[(j0+2)+nao*(k0+3)];
            d_16 = dm[(j0+2)+nao*(k0+4)];
            d_17 = dm[(j0+2)+nao*(k0+5)];
            atomicAdd(vk+(i0+0)+nao*(l0+0), gout0*d_0+gout1*d_1+gout2*d_2+gout3*d_3+gout4*d_4+gout5*d_5+gout6*d_6+gout7*d_7+gout8*d_8+gout9*d_9+gout10*d_10+gout11*d_11+gout12*d_12+gout13*d_13+gout14*d_14+gout15*d_15+gout16*d_16+gout17*d_17);
            atomicAdd(vk+(i0+1)+nao*(l0+0), gout18*d_0+gout19*d_1+gout20*d_2+gout21*d_3+gout22*d_4+gout23*d_5+gout24*d_6+gout25*d_7+gout26*d_8+gout27*d_9+gout28*d_10+gout29*d_11+gout30*d_12+gout31*d_13+gout32*d_14+gout33*d_15+gout34*d_16+gout35*d_17);
            atomicAdd(vk+(i0+2)+nao*(l0+0), gout36*d_0+gout37*d_1+gout38*d_2+gout39*d_3+gout40*d_4+gout41*d_5+gout42*d_6+gout43*d_7+gout44*d_8+gout45*d_9+gout46*d_10+gout47*d_11+gout48*d_12+gout49*d_13+gout50*d_14+gout51*d_15+gout52*d_16+gout53*d_17);
            atomicAdd(vk+(i0+0)+nao*(l0+0)+nao2, gout54*d_0+gout55*d_1+gout56*d_2+gout57*d_3+gout58*d_4+gout59*d_5+gout60*d_6+gout61*d_7+gout62*d_8+gout63*d_9+gout64*d_10+gout65*d_11+gout66*d_12+gout67*d_13+gout68*d_14+gout69*d_15+gout70*d_16+gout71*d_17);
            atomicAdd(vk+(i0+1)+nao*(l0+0)+nao2, gout72*d_0+gout73*d_1+gout74*d_2+gout75*d_3+gout76*d_4+gout77*d_5+gout78*d_6+gout79*d_7+gout80*d_8+gout81*d_9+gout82*d_10+gout83*d_11+gout84*d_12+gout85*d_13+gout86*d_14+gout87*d_15+gout88*d_16+gout89*d_17);
            atomicAdd(vk+(i0+2)+nao*(l0+0)+nao2, gout90*d_0+gout91*d_1+gout92*d_2+gout93*d_3+gout94*d_4+gout95*d_5+gout96*d_6+gout97*d_7+gout98*d_8+gout99*d_9+gout100*d_10+gout101*d_11+gout102*d_12+gout103*d_13+gout104*d_14+gout105*d_15+gout106*d_16+gout107*d_17);
            atomicAdd(vk+(i0+0)+nao*(l0+0)+2*nao2, gout108*d_0+gout109*d_1+gout110*d_2+gout111*d_3+gout112*d_4+gout113*d_5+gout114*d_6+gout115*d_7+gout116*d_8+gout117*d_9+gout118*d_10+gout119*d_11+gout120*d_12+gout121*d_13+gout122*d_14+gout123*d_15+gout124*d_16+gout125*d_17);
            atomicAdd(vk+(i0+1)+nao*(l0+0)+2*nao2, gout126*d_0+gout127*d_1+gout128*d_2+gout129*d_3+gout130*d_4+gout131*d_5+gout132*d_6+gout133*d_7+gout134*d_8+gout135*d_9+gout136*d_10+gout137*d_11+gout138*d_12+gout139*d_13+gout140*d_14+gout141*d_15+gout142*d_16+gout143*d_17);
            atomicAdd(vk+(i0+2)+nao*(l0+0)+2*nao2, gout144*d_0+gout145*d_1+gout146*d_2+gout147*d_3+gout148*d_4+gout149*d_5+gout150*d_6+gout151*d_7+gout152*d_8+gout153*d_9+gout154*d_10+gout155*d_11+gout156*d_12+gout157*d_13+gout158*d_14+gout159*d_15+gout160*d_16+gout161*d_17);
            // ijkl, jl -> ik
            d_0 = dm[(j0+0)+nao*(l0+0)];
            d_1 = dm[(j0+1)+nao*(l0+0)];
            d_2 = dm[(j0+2)+nao*(l0+0)];
            atomicAdd(vk+(i0+0)+nao*(k0+0), gout0*d_0+gout6*d_1+gout12*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+1), gout1*d_0+gout7*d_1+gout13*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+2), gout2*d_0+gout8*d_1+gout14*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+3), gout3*d_0+gout9*d_1+gout15*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+4), gout4*d_0+gout10*d_1+gout16*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+5), gout5*d_0+gout11*d_1+gout17*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+0), gout18*d_0+gout24*d_1+gout30*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+1), gout19*d_0+gout25*d_1+gout31*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+2), gout20*d_0+gout26*d_1+gout32*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+3), gout21*d_0+gout27*d_1+gout33*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+4), gout22*d_0+gout28*d_1+gout34*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+5), gout23*d_0+gout29*d_1+gout35*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+0), gout36*d_0+gout42*d_1+gout48*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+1), gout37*d_0+gout43*d_1+gout49*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+2), gout38*d_0+gout44*d_1+gout50*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+3), gout39*d_0+gout45*d_1+gout51*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+4), gout40*d_0+gout46*d_1+gout52*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+5), gout41*d_0+gout47*d_1+gout53*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+0)+nao2, gout54*d_0+gout60*d_1+gout66*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+1)+nao2, gout55*d_0+gout61*d_1+gout67*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+2)+nao2, gout56*d_0+gout62*d_1+gout68*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+3)+nao2, gout57*d_0+gout63*d_1+gout69*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+4)+nao2, gout58*d_0+gout64*d_1+gout70*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+5)+nao2, gout59*d_0+gout65*d_1+gout71*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+0)+nao2, gout72*d_0+gout78*d_1+gout84*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+1)+nao2, gout73*d_0+gout79*d_1+gout85*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+2)+nao2, gout74*d_0+gout80*d_1+gout86*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+3)+nao2, gout75*d_0+gout81*d_1+gout87*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+4)+nao2, gout76*d_0+gout82*d_1+gout88*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+5)+nao2, gout77*d_0+gout83*d_1+gout89*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+0)+nao2, gout90*d_0+gout96*d_1+gout102*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+1)+nao2, gout91*d_0+gout97*d_1+gout103*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+2)+nao2, gout92*d_0+gout98*d_1+gout104*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+3)+nao2, gout93*d_0+gout99*d_1+gout105*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+4)+nao2, gout94*d_0+gout100*d_1+gout106*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+5)+nao2, gout95*d_0+gout101*d_1+gout107*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+0)+2*nao2, gout108*d_0+gout114*d_1+gout120*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+1)+2*nao2, gout109*d_0+gout115*d_1+gout121*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+2)+2*nao2, gout110*d_0+gout116*d_1+gout122*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+3)+2*nao2, gout111*d_0+gout117*d_1+gout123*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+4)+2*nao2, gout112*d_0+gout118*d_1+gout124*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+5)+2*nao2, gout113*d_0+gout119*d_1+gout125*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+0)+2*nao2, gout126*d_0+gout132*d_1+gout138*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+1)+2*nao2, gout127*d_0+gout133*d_1+gout139*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+2)+2*nao2, gout128*d_0+gout134*d_1+gout140*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+3)+2*nao2, gout129*d_0+gout135*d_1+gout141*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+4)+2*nao2, gout130*d_0+gout136*d_1+gout142*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+5)+2*nao2, gout131*d_0+gout137*d_1+gout143*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+0)+2*nao2, gout144*d_0+gout150*d_1+gout156*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+1)+2*nao2, gout145*d_0+gout151*d_1+gout157*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+2)+2*nao2, gout146*d_0+gout152*d_1+gout158*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+3)+2*nao2, gout147*d_0+gout153*d_1+gout159*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+4)+2*nao2, gout148*d_0+gout154*d_1+gout160*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+5)+2*nao2, gout149*d_0+gout155*d_1+gout161*d_2);
            // ijkl, ik -> jl
            d_0 = dm[(i0+0)+nao*(k0+0)];
            d_1 = dm[(i0+0)+nao*(k0+1)];
            d_2 = dm[(i0+0)+nao*(k0+2)];
            d_3 = dm[(i0+0)+nao*(k0+3)];
            d_4 = dm[(i0+0)+nao*(k0+4)];
            d_5 = dm[(i0+0)+nao*(k0+5)];
            d_6 = dm[(i0+1)+nao*(k0+0)];
            d_7 = dm[(i0+1)+nao*(k0+1)];
            d_8 = dm[(i0+1)+nao*(k0+2)];
            d_9 = dm[(i0+1)+nao*(k0+3)];
            d_10 = dm[(i0+1)+nao*(k0+4)];
            d_11 = dm[(i0+1)+nao*(k0+5)];
            d_12 = dm[(i0+2)+nao*(k0+0)];
            d_13 = dm[(i0+2)+nao*(k0+1)];
            d_14 = dm[(i0+2)+nao*(k0+2)];
            d_15 = dm[(i0+2)+nao*(k0+3)];
            d_16 = dm[(i0+2)+nao*(k0+4)];
            d_17 = dm[(i0+2)+nao*(k0+5)];
            atomicAdd(vk+(j0+0)+nao*(l0+0), gout162*d_0+gout163*d_1+gout164*d_2+gout165*d_3+gout166*d_4+gout167*d_5+gout180*d_6+gout181*d_7+gout182*d_8+gout183*d_9+gout184*d_10+gout185*d_11+gout198*d_12+gout199*d_13+gout200*d_14+gout201*d_15+gout202*d_16+gout203*d_17);
            atomicAdd(vk+(j0+1)+nao*(l0+0), gout168*d_0+gout169*d_1+gout170*d_2+gout171*d_3+gout172*d_4+gout173*d_5+gout186*d_6+gout187*d_7+gout188*d_8+gout189*d_9+gout190*d_10+gout191*d_11+gout204*d_12+gout205*d_13+gout206*d_14+gout207*d_15+gout208*d_16+gout209*d_17);
            atomicAdd(vk+(j0+2)+nao*(l0+0), gout174*d_0+gout175*d_1+gout176*d_2+gout177*d_3+gout178*d_4+gout179*d_5+gout192*d_6+gout193*d_7+gout194*d_8+gout195*d_9+gout196*d_10+gout197*d_11+gout210*d_12+gout211*d_13+gout212*d_14+gout213*d_15+gout214*d_16+gout215*d_17);
            atomicAdd(vk+(j0+0)+nao*(l0+0)+nao2, gout216*d_0+gout217*d_1+gout218*d_2+gout219*d_3+gout220*d_4+gout221*d_5+gout234*d_6+gout235*d_7+gout236*d_8+gout237*d_9+gout238*d_10+gout239*d_11+gout252*d_12+gout253*d_13+gout254*d_14+gout255*d_15+gout256*d_16+gout257*d_17);
            atomicAdd(vk+(j0+1)+nao*(l0+0)+nao2, gout222*d_0+gout223*d_1+gout224*d_2+gout225*d_3+gout226*d_4+gout227*d_5+gout240*d_6+gout241*d_7+gout242*d_8+gout243*d_9+gout244*d_10+gout245*d_11+gout258*d_12+gout259*d_13+gout260*d_14+gout261*d_15+gout262*d_16+gout263*d_17);
            atomicAdd(vk+(j0+2)+nao*(l0+0)+nao2, gout228*d_0+gout229*d_1+gout230*d_2+gout231*d_3+gout232*d_4+gout233*d_5+gout246*d_6+gout247*d_7+gout248*d_8+gout249*d_9+gout250*d_10+gout251*d_11+gout264*d_12+gout265*d_13+gout266*d_14+gout267*d_15+gout268*d_16+gout269*d_17);
            atomicAdd(vk+(j0+0)+nao*(l0+0)+2*nao2, gout270*d_0+gout271*d_1+gout272*d_2+gout273*d_3+gout274*d_4+gout275*d_5+gout288*d_6+gout289*d_7+gout290*d_8+gout291*d_9+gout292*d_10+gout293*d_11+gout306*d_12+gout307*d_13+gout308*d_14+gout309*d_15+gout310*d_16+gout311*d_17);
            atomicAdd(vk+(j0+1)+nao*(l0+0)+2*nao2, gout276*d_0+gout277*d_1+gout278*d_2+gout279*d_3+gout280*d_4+gout281*d_5+gout294*d_6+gout295*d_7+gout296*d_8+gout297*d_9+gout298*d_10+gout299*d_11+gout312*d_12+gout313*d_13+gout314*d_14+gout315*d_15+gout316*d_16+gout317*d_17);
            atomicAdd(vk+(j0+2)+nao*(l0+0)+2*nao2, gout282*d_0+gout283*d_1+gout284*d_2+gout285*d_3+gout286*d_4+gout287*d_5+gout300*d_6+gout301*d_7+gout302*d_8+gout303*d_9+gout304*d_10+gout305*d_11+gout318*d_12+gout319*d_13+gout320*d_14+gout321*d_15+gout322*d_16+gout323*d_17);
            // ijkl, il -> jk
            d_0 = dm[(i0+0)+nao*(l0+0)];
            d_1 = dm[(i0+1)+nao*(l0+0)];
            d_2 = dm[(i0+2)+nao*(l0+0)];
            atomicAdd(vk+(j0+0)+nao*(k0+0), gout162*d_0+gout180*d_1+gout198*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+1), gout163*d_0+gout181*d_1+gout199*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+2), gout164*d_0+gout182*d_1+gout200*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+3), gout165*d_0+gout183*d_1+gout201*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+4), gout166*d_0+gout184*d_1+gout202*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+5), gout167*d_0+gout185*d_1+gout203*d_2);
            atomicAdd(vk+(j0+1)+nao*(k0+0), gout168*d_0+gout186*d_1+gout204*d_2);
            atomicAdd(vk+(j0+1)+nao*(k0+1), gout169*d_0+gout187*d_1+gout205*d_2);
            atomicAdd(vk+(j0+1)+nao*(k0+2), gout170*d_0+gout188*d_1+gout206*d_2);
            atomicAdd(vk+(j0+1)+nao*(k0+3), gout171*d_0+gout189*d_1+gout207*d_2);
            atomicAdd(vk+(j0+1)+nao*(k0+4), gout172*d_0+gout190*d_1+gout208*d_2);
            atomicAdd(vk+(j0+1)+nao*(k0+5), gout173*d_0+gout191*d_1+gout209*d_2);
            atomicAdd(vk+(j0+2)+nao*(k0+0), gout174*d_0+gout192*d_1+gout210*d_2);
            atomicAdd(vk+(j0+2)+nao*(k0+1), gout175*d_0+gout193*d_1+gout211*d_2);
            atomicAdd(vk+(j0+2)+nao*(k0+2), gout176*d_0+gout194*d_1+gout212*d_2);
            atomicAdd(vk+(j0+2)+nao*(k0+3), gout177*d_0+gout195*d_1+gout213*d_2);
            atomicAdd(vk+(j0+2)+nao*(k0+4), gout178*d_0+gout196*d_1+gout214*d_2);
            atomicAdd(vk+(j0+2)+nao*(k0+5), gout179*d_0+gout197*d_1+gout215*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+0)+nao2, gout216*d_0+gout234*d_1+gout252*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+1)+nao2, gout217*d_0+gout235*d_1+gout253*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+2)+nao2, gout218*d_0+gout236*d_1+gout254*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+3)+nao2, gout219*d_0+gout237*d_1+gout255*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+4)+nao2, gout220*d_0+gout238*d_1+gout256*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+5)+nao2, gout221*d_0+gout239*d_1+gout257*d_2);
            atomicAdd(vk+(j0+1)+nao*(k0+0)+nao2, gout222*d_0+gout240*d_1+gout258*d_2);
            atomicAdd(vk+(j0+1)+nao*(k0+1)+nao2, gout223*d_0+gout241*d_1+gout259*d_2);
            atomicAdd(vk+(j0+1)+nao*(k0+2)+nao2, gout224*d_0+gout242*d_1+gout260*d_2);
            atomicAdd(vk+(j0+1)+nao*(k0+3)+nao2, gout225*d_0+gout243*d_1+gout261*d_2);
            atomicAdd(vk+(j0+1)+nao*(k0+4)+nao2, gout226*d_0+gout244*d_1+gout262*d_2);
            atomicAdd(vk+(j0+1)+nao*(k0+5)+nao2, gout227*d_0+gout245*d_1+gout263*d_2);
            atomicAdd(vk+(j0+2)+nao*(k0+0)+nao2, gout228*d_0+gout246*d_1+gout264*d_2);
            atomicAdd(vk+(j0+2)+nao*(k0+1)+nao2, gout229*d_0+gout247*d_1+gout265*d_2);
            atomicAdd(vk+(j0+2)+nao*(k0+2)+nao2, gout230*d_0+gout248*d_1+gout266*d_2);
            atomicAdd(vk+(j0+2)+nao*(k0+3)+nao2, gout231*d_0+gout249*d_1+gout267*d_2);
            atomicAdd(vk+(j0+2)+nao*(k0+4)+nao2, gout232*d_0+gout250*d_1+gout268*d_2);
            atomicAdd(vk+(j0+2)+nao*(k0+5)+nao2, gout233*d_0+gout251*d_1+gout269*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+0)+2*nao2, gout270*d_0+gout288*d_1+gout306*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+1)+2*nao2, gout271*d_0+gout289*d_1+gout307*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+2)+2*nao2, gout272*d_0+gout290*d_1+gout308*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+3)+2*nao2, gout273*d_0+gout291*d_1+gout309*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+4)+2*nao2, gout274*d_0+gout292*d_1+gout310*d_2);
            atomicAdd(vk+(j0+0)+nao*(k0+5)+2*nao2, gout275*d_0+gout293*d_1+gout311*d_2);
            atomicAdd(vk+(j0+1)+nao*(k0+0)+2*nao2, gout276*d_0+gout294*d_1+gout312*d_2);
            atomicAdd(vk+(j0+1)+nao*(k0+1)+2*nao2, gout277*d_0+gout295*d_1+gout313*d_2);
            atomicAdd(vk+(j0+1)+nao*(k0+2)+2*nao2, gout278*d_0+gout296*d_1+gout314*d_2);
            atomicAdd(vk+(j0+1)+nao*(k0+3)+2*nao2, gout279*d_0+gout297*d_1+gout315*d_2);
            atomicAdd(vk+(j0+1)+nao*(k0+4)+2*nao2, gout280*d_0+gout298*d_1+gout316*d_2);
            atomicAdd(vk+(j0+1)+nao*(k0+5)+2*nao2, gout281*d_0+gout299*d_1+gout317*d_2);
            atomicAdd(vk+(j0+2)+nao*(k0+0)+2*nao2, gout282*d_0+gout300*d_1+gout318*d_2);
            atomicAdd(vk+(j0+2)+nao*(k0+1)+2*nao2, gout283*d_0+gout301*d_1+gout319*d_2);
            atomicAdd(vk+(j0+2)+nao*(k0+2)+2*nao2, gout284*d_0+gout302*d_1+gout320*d_2);
            atomicAdd(vk+(j0+2)+nao*(k0+3)+2*nao2, gout285*d_0+gout303*d_1+gout321*d_2);
            atomicAdd(vk+(j0+2)+nao*(k0+4)+2*nao2, gout286*d_0+gout304*d_1+gout322*d_2);
            atomicAdd(vk+(j0+2)+nao*(k0+5)+2*nao2, gout287*d_0+gout305*d_1+gout323*d_2);
            vk += 3*nao2;
        }
        dm += nao2;
    }
}

__global__
static void GINTint2e_ip1_jk_kernel_2010(GINTEnvVars envs, JKMatrix jk,
                                    BasisProdOffsets offsets)
{
    int ntasks_ij = offsets.ntasks_ij;
    int ntasks_kl = offsets.ntasks_kl;
    int task_ij = blockIdx.x * blockDim.x + threadIdx.x;
    int task_kl = blockIdx.y * blockDim.y + threadIdx.y;
    if (task_ij >= ntasks_ij || task_kl >= ntasks_kl) {
        return;
    }
    int bas_ij = offsets.bas_ij + task_ij;
    int bas_kl = offsets.bas_kl + task_kl;
    double norm = envs.fac;
    double omega = envs.omega;
    int *bas_pair2bra = c_bpcache.bas_pair2bra;
    int *bas_pair2ket = c_bpcache.bas_pair2ket;
    int ish = bas_pair2bra[bas_ij];
    int jsh = bas_pair2ket[bas_ij];
    int ksh = bas_pair2bra[bas_kl];
    int lsh = bas_pair2ket[bas_kl];
    int nprim_ij = envs.nprim_ij;
    int nprim_kl = envs.nprim_kl;
    int prim_ij = offsets.primitive_ij + task_ij * nprim_ij;
    int prim_kl = offsets.primitive_kl + task_kl * nprim_kl;

    double* __restrict__ a12 = c_bpcache.a12;
    double* __restrict__ e12 = c_bpcache.e12;
    double* __restrict__ x12 = c_bpcache.x12;
    double* __restrict__ y12 = c_bpcache.y12;
    double* __restrict__ z12 = c_bpcache.z12;
    double * __restrict__ i_exponent = c_bpcache.a1;
    double * __restrict__ j_exponent = c_bpcache.a2;

    int ij, kl;
    int prim_ij0, prim_ij1, prim_kl0, prim_kl1;
    int nbas = c_bpcache.nbas;
    double* __restrict__ bas_x = c_bpcache.bas_coords;
    double* __restrict__ bas_y = bas_x + nbas;
    double* __restrict__ bas_z = bas_y + nbas;

    double gout0 = 0;
    double gout1 = 0;
    double gout2 = 0;
    double gout3 = 0;
    double gout4 = 0;
    double gout5 = 0;
    double gout6 = 0;
    double gout7 = 0;
    double gout8 = 0;
    double gout9 = 0;
    double gout10 = 0;
    double gout11 = 0;
    double gout12 = 0;
    double gout13 = 0;
    double gout14 = 0;
    double gout15 = 0;
    double gout16 = 0;
    double gout17 = 0;
    double gout18 = 0;
    double gout19 = 0;
    double gout20 = 0;
    double gout21 = 0;
    double gout22 = 0;
    double gout23 = 0;
    double gout24 = 0;
    double gout25 = 0;
    double gout26 = 0;
    double gout27 = 0;
    double gout28 = 0;
    double gout29 = 0;
    double gout30 = 0;
    double gout31 = 0;
    double gout32 = 0;
    double gout33 = 0;
    double gout34 = 0;
    double gout35 = 0;
    double gout36 = 0;
    double gout37 = 0;
    double gout38 = 0;
    double gout39 = 0;
    double gout40 = 0;
    double gout41 = 0;
    double gout42 = 0;
    double gout43 = 0;
    double gout44 = 0;
    double gout45 = 0;
    double gout46 = 0;
    double gout47 = 0;
    double gout48 = 0;
    double gout49 = 0;
    double gout50 = 0;
    double gout51 = 0;
    double gout52 = 0;
    double gout53 = 0;
    double gout54 = 0;
    double gout55 = 0;
    double gout56 = 0;
    double gout57 = 0;
    double gout58 = 0;
    double gout59 = 0;
    double gout60 = 0;
    double gout61 = 0;
    double gout62 = 0;
    double gout63 = 0;
    double gout64 = 0;
    double gout65 = 0;
    double gout66 = 0;
    double gout67 = 0;
    double gout68 = 0;
    double gout69 = 0;
    double gout70 = 0;
    double gout71 = 0;
    double gout72 = 0;
    double gout73 = 0;
    double gout74 = 0;
    double gout75 = 0;
    double gout76 = 0;
    double gout77 = 0;
    double gout78 = 0;
    double gout79 = 0;
    double gout80 = 0;
    double gout81 = 0;
    double gout82 = 0;
    double gout83 = 0;
    double gout84 = 0;
    double gout85 = 0;
    double gout86 = 0;
    double gout87 = 0;
    double gout88 = 0;
    double gout89 = 0;
    double gout90 = 0;
    double gout91 = 0;
    double gout92 = 0;
    double gout93 = 0;
    double gout94 = 0;
    double gout95 = 0;
    double gout96 = 0;
    double gout97 = 0;
    double gout98 = 0;
    double gout99 = 0;
    double gout100 = 0;
    double gout101 = 0;
    double gout102 = 0;
    double gout103 = 0;
    double gout104 = 0;
    double gout105 = 0;
    double gout106 = 0;
    double gout107 = 0;

    double xi = bas_x[ish];
    double yi = bas_y[ish];
    double zi = bas_z[ish];
    double ABx = xi - bas_x[jsh];
    double ABy = yi - bas_y[jsh];
    double ABz = zi - bas_z[jsh];
    double xk = bas_x[ksh];
    double yk = bas_y[ksh];
    double zk = bas_z[ksh];

    prim_ij0 = prim_ij;
    prim_ij1 = prim_ij + nprim_ij;
    prim_kl0 = prim_kl;
    prim_kl1 = prim_kl + nprim_kl;
    double rw[6];
    int irys;
    for (ij = prim_ij0; ij < prim_ij1; ++ij) {
        double alpha = i_exponent[ij];
        double beta = j_exponent[ij];
        double aij = a12[ij];
        double eij = e12[ij];
        double xij = x12[ij];
        double yij = y12[ij];
        double zij = z12[ij];
    for (kl = prim_kl0; kl < prim_kl1; ++kl) {
        double akl = a12[kl];
        double ekl = e12[kl];
        double xkl = x12[kl];
        double ykl = y12[kl];
        double zkl = z12[kl];
        double xijxkl = xij - xkl;
        double yijykl = yij - ykl;
        double zijzkl = zij - zkl;
        double aijkl = aij + akl;
        double a1 = aij * akl;
        double a0 = a1 / aijkl;
        double theta = omega > 0.0 ? omega * omega / (omega * omega + a0) : 1.0; 
        a0 *= theta;
        double x = a0 * (xijxkl * xijxkl + yijykl * yijykl + zijzkl * zijzkl);
        double fac = norm * eij * ekl * sqrt(a0 / (a1 * a1 * a1));
        //double fac = norm * eij * ekl / (sqrt(aijkl) * a1);

        GINTrys_root<3>(x, rw);
        GINTscale_u<3>(rw, theta);
      for (irys = 0; irys < 3; ++irys) {
            double weight0 = rw[irys+3] * fac;
            double root0 = rw[irys];
            double u2 = a0 * root0;
            double tmp4 = .5 / (u2 * aijkl + a1);
            double B00 = u2 * tmp4;
            double tmp1 = 2 * B00;
            double B10 = B00 + tmp4 * akl;
            double tmp2 = tmp1 * akl;
            double C00x = xij - xi - tmp2 * xijxkl;
            double C00y = yij - yi - tmp2 * yijykl;
            double C00z = zij - zi - tmp2 * zijzkl;

            double tmp3 = tmp1 * aij;
            double D00x = xkl - xk + tmp3 * xijxkl;
            double D00y = ykl - yk + tmp3 * yijykl;
            double D00z = zkl - zk + tmp3 * zijzkl;

            double g0 = B10+C00x*C00x;
            double g1 = 3*B10*C00x;
            double g2 = g1+C00x*C00x*C00x;
            double g3 = C00x*D00x;
            double g4 = B00+g3;
            double g5 = 2*B00*C00x;
            double g6 = g0*D00x;
            double g7 = g5+g6;
            double g8 = 3*B00*g0;
            double g9 = 3*B10;
            double g12 = g8+(C00x*(g9+C00x*C00x)*D00x);
            double g13 = ABx+C00x;
            double g15 = B10+(C00x*g13);
            double g17 = g1+C00x*C00x*C00x+(ABx*g0);
            double g19 = B00+(g13*D00x);
            double g24 = (B00*(ABx+(2*C00x)))+(g15*D00x);
            double g32 = (B00*(g9+(C00x*((2*ABx)+(3*C00x)))))+(g17*D00x);
            double g33 = B10+C00y*C00y;
            double g34 = 3*B10*C00y;
            double g35 = g34+C00y*C00y*C00y;
            double g37 = B00+(C00y*D00y);
            double g40 = (2*B00*C00y)+(g33*D00y);
            double g44 = (3*B00*g33)+(C00y*(g9+C00y*C00y)*D00y);
            double g45 = ABy+C00y;
            double g47 = B10+(C00y*g45);
            double g49 = g34+C00y*C00y*C00y+(ABy*g33);
            double g51 = B00+(g45*D00y);
            double g56 = (B00*(ABy+(2*C00y)))+(g47*D00y);
            double g64 = (B00*(g9+(C00y*((2*ABy)+(3*C00y)))))+(g49*D00y);
            double g65 = B10+C00z*C00z;
            double g66 = 3*B10*C00z;
            double g67 = g66+C00z*C00z*C00z;
            double g69 = B00+(C00z*D00z);
            double g72 = (2*B00*C00z)+(g65*D00z);
            double g76 = (3*B00*g65)+(C00z*(g9+C00z*C00z)*D00z);
            double g77 = ABz+C00z;
            double g79 = B10+(C00z*g77);
            double g81 = g66+C00z*C00z*C00z+(ABz*g65);
            double g83 = B00+(g77*D00z);
            double g88 = (B00*(ABz+(2*C00z)))+(g79*D00z);
            double g96 = (B00*(g9+(C00z*((2*ABz)+(3*C00z)))))+(g81*D00z);

            gout0 += (-2*g4 + 2*alpha*g12) * weight0;
            gout1 += (-2*C00x + 2*alpha*g2) * (D00y) * weight0;
            gout2 += (-2*C00x + 2*alpha*g2) * (D00z) * weight0;
            gout3 += (-D00x + 2*alpha*g7) * (C00y) * weight0;
            gout4 += (-1 + 2*alpha*g0) * (g37) * weight0;
            gout5 += (-1 + 2*alpha*g0) * (C00y) * (D00z) * weight0;
            gout6 += (-D00x + 2*alpha*g7) * (C00z) * weight0;
            gout7 += (-1 + 2*alpha*g0) * (D00y) * (C00z) * weight0;
            gout8 += (-1 + 2*alpha*g0) * (g69) * weight0;
            gout9 += (2*alpha*g4) * (g33) * weight0;
            gout10 += (2*alpha*C00x) * (g40) * weight0;
            gout11 += (2*alpha*C00x) * (g33) * (D00z) * weight0;
            gout12 += (2*alpha*g4) * (C00y) * (C00z) * weight0;
            gout13 += (2*alpha*C00x) * (g37) * (C00z) * weight0;
            gout14 += (2*alpha*C00x) * (C00y) * (g69) * weight0;
            gout15 += (2*alpha*g4) * (g65) * weight0;
            gout16 += (2*alpha*C00x) * (D00y) * (g65) * weight0;
            gout17 += (2*alpha*C00x) * (g72) * weight0;
            gout18 += (g7) * (2*alpha*C00y) * weight0;
            gout19 += (g0) * (2*alpha*g37) * weight0;
            gout20 += (g0) * (2*alpha*C00y) * (D00z) * weight0;
            gout21 += (g4) * (-1 + 2*alpha*g33) * weight0;
            gout22 += (C00x) * (-D00y + 2*alpha*g40) * weight0;
            gout23 += (C00x) * (-1 + 2*alpha*g33) * (D00z) * weight0;
            gout24 += (g4) * (2*alpha*C00y) * (C00z) * weight0;
            gout25 += (C00x) * (2*alpha*g37) * (C00z) * weight0;
            gout26 += (C00x) * (2*alpha*C00y) * (g69) * weight0;
            gout27 += (D00x) * (-2*C00y + 2*alpha*g35) * weight0;
            gout28 += (-2*g37 + 2*alpha*g44) * weight0;
            gout29 += (-2*C00y + 2*alpha*g35) * (D00z) * weight0;
            gout30 += (D00x) * (-1 + 2*alpha*g33) * (C00z) * weight0;
            gout31 += (-D00y + 2*alpha*g40) * (C00z) * weight0;
            gout32 += (-1 + 2*alpha*g33) * (g69) * weight0;
            gout33 += (D00x) * (2*alpha*C00y) * (g65) * weight0;
            gout34 += (2*alpha*g37) * (g65) * weight0;
            gout35 += (2*alpha*C00y) * (g72) * weight0;
            gout36 += (g7) * (2*alpha*C00z) * weight0;
            gout37 += (g0) * (D00y) * (2*alpha*C00z) * weight0;
            gout38 += (g0) * (2*alpha*g69) * weight0;
            gout39 += (g4) * (C00y) * (2*alpha*C00z) * weight0;
            gout40 += (C00x) * (g37) * (2*alpha*C00z) * weight0;
            gout41 += (C00x) * (C00y) * (2*alpha*g69) * weight0;
            gout42 += (g4) * (-1 + 2*alpha*g65) * weight0;
            gout43 += (C00x) * (D00y) * (-1 + 2*alpha*g65) * weight0;
            gout44 += (C00x) * (-D00z + 2*alpha*g72) * weight0;
            gout45 += (D00x) * (g33) * (2*alpha*C00z) * weight0;
            gout46 += (g40) * (2*alpha*C00z) * weight0;
            gout47 += (g33) * (2*alpha*g69) * weight0;
            gout48 += (D00x) * (C00y) * (-1 + 2*alpha*g65) * weight0;
            gout49 += (g37) * (-1 + 2*alpha*g65) * weight0;
            gout50 += (C00y) * (-D00z + 2*alpha*g72) * weight0;
            gout51 += (D00x) * (-2*C00z + 2*alpha*g67) * weight0;
            gout52 += (D00y) * (-2*C00z + 2*alpha*g67) * weight0;
            gout53 += (-2*g69 + 2*alpha*g76) * weight0;
            gout54 += (2*beta*g32) * weight0;
            gout55 += (2*beta*g17) * (D00y) * weight0;
            gout56 += (2*beta*g17) * (D00z) * weight0;
            gout57 += (2*beta*g24) * (C00y) * weight0;
            gout58 += (2*beta*g15) * (g37) * weight0;
            gout59 += (2*beta*g15) * (C00y) * (D00z) * weight0;
            gout60 += (2*beta*g24) * (C00z) * weight0;
            gout61 += (2*beta*g15) * (D00y) * (C00z) * weight0;
            gout62 += (2*beta*g15) * (g69) * weight0;
            gout63 += (2*beta*g19) * (g33) * weight0;
            gout64 += (2*beta*g13) * (g40) * weight0;
            gout65 += (2*beta*g13) * (g33) * (D00z) * weight0;
            gout66 += (2*beta*g19) * (C00y) * (C00z) * weight0;
            gout67 += (2*beta*g13) * (g37) * (C00z) * weight0;
            gout68 += (2*beta*g13) * (C00y) * (g69) * weight0;
            gout69 += (2*beta*g19) * (g65) * weight0;
            gout70 += (2*beta*g13) * (D00y) * (g65) * weight0;
            gout71 += (2*beta*g13) * (g72) * weight0;
            gout72 += (g7) * (2*beta*g45) * weight0;
            gout73 += (g0) * (2*beta*g51) * weight0;
            gout74 += (g0) * (2*beta*g45) * (D00z) * weight0;
            gout75 += (g4) * (2*beta*g47) * weight0;
            gout76 += (C00x) * (2*beta*g56) * weight0;
            gout77 += (C00x) * (2*beta*g47) * (D00z) * weight0;
            gout78 += (g4) * (2*beta*g45) * (C00z) * weight0;
            gout79 += (C00x) * (2*beta*g51) * (C00z) * weight0;
            gout80 += (C00x) * (2*beta*g45) * (g69) * weight0;
            gout81 += (D00x) * (2*beta*g49) * weight0;
            gout82 += (2*beta*g64) * weight0;
            gout83 += (2*beta*g49) * (D00z) * weight0;
            gout84 += (D00x) * (2*beta*g47) * (C00z) * weight0;
            gout85 += (2*beta*g56) * (C00z) * weight0;
            gout86 += (2*beta*g47) * (g69) * weight0;
            gout87 += (D00x) * (2*beta*g45) * (g65) * weight0;
            gout88 += (2*beta*g51) * (g65) * weight0;
            gout89 += (2*beta*g45) * (g72) * weight0;
            gout90 += (g7) * (2*beta*g77) * weight0;
            gout91 += (g0) * (D00y) * (2*beta*g77) * weight0;
            gout92 += (g0) * (2*beta*g83) * weight0;
            gout93 += (g4) * (C00y) * (2*beta*g77) * weight0;
            gout94 += (C00x) * (g37) * (2*beta*g77) * weight0;
            gout95 += (C00x) * (C00y) * (2*beta*g83) * weight0;
            gout96 += (g4) * (2*beta*g79) * weight0;
            gout97 += (C00x) * (D00y) * (2*beta*g79) * weight0;
            gout98 += (C00x) * (2*beta*g88) * weight0;
            gout99 += (D00x) * (g33) * (2*beta*g77) * weight0;
            gout100 += (g40) * (2*beta*g77) * weight0;
            gout101 += (g33) * (2*beta*g83) * weight0;
            gout102 += (D00x) * (C00y) * (2*beta*g79) * weight0;
            gout103 += (g37) * (2*beta*g79) * weight0;
            gout104 += (C00y) * (2*beta*g88) * weight0;
            gout105 += (D00x) * (2*beta*g81) * weight0;
            gout106 += (D00y) * (2*beta*g81) * weight0;
            gout107 += (2*beta*g96) * weight0;
        }
    } }

    int *ao_loc = c_bpcache.ao_loc;
    int i0 = ao_loc[ish];
    int j0 = ao_loc[jsh];
    int k0 = ao_loc[ksh];
    int l0 = ao_loc[lsh];
    int n_dm = jk.n_dm;
    int nao = jk.nao;
    size_t nao2 = nao * nao;
    double* __restrict__ dm = jk.dm;
    double *vj = jk.vj;
    double *vk = jk.vk;
    double d_0, d_1, d_2, d_3, d_4, d_5, d_6, d_7, d_8, d_9, d_10, d_11, d_12, d_13, d_14, d_15, d_16, d_17;

    for (int i_dm = 0; i_dm < n_dm; ++i_dm) {
        if (vj != NULL) {
            d_0 = dm[(k0+0)+nao*(l0+0)];
            d_1 = dm[(k0+1)+nao*(l0+0)];
            d_2 = dm[(k0+2)+nao*(l0+0)];
            atomicAdd(vj+(i0+0)+nao*(j0+0), gout0*d_0+gout1*d_1+gout2*d_2);
            atomicAdd(vj+(i0+1)+nao*(j0+0), gout3*d_0+gout4*d_1+gout5*d_2);
            atomicAdd(vj+(i0+2)+nao*(j0+0), gout6*d_0+gout7*d_1+gout8*d_2);
            atomicAdd(vj+(i0+3)+nao*(j0+0), gout9*d_0+gout10*d_1+gout11*d_2);
            atomicAdd(vj+(i0+4)+nao*(j0+0), gout12*d_0+gout13*d_1+gout14*d_2);
            atomicAdd(vj+(i0+5)+nao*(j0+0), gout15*d_0+gout16*d_1+gout17*d_2);
            atomicAdd(vj+(i0+0)+nao*(j0+0)+nao2, gout18*d_0+gout19*d_1+gout20*d_2);
            atomicAdd(vj+(i0+1)+nao*(j0+0)+nao2, gout21*d_0+gout22*d_1+gout23*d_2);
            atomicAdd(vj+(i0+2)+nao*(j0+0)+nao2, gout24*d_0+gout25*d_1+gout26*d_2);
            atomicAdd(vj+(i0+3)+nao*(j0+0)+nao2, gout27*d_0+gout28*d_1+gout29*d_2);
            atomicAdd(vj+(i0+4)+nao*(j0+0)+nao2, gout30*d_0+gout31*d_1+gout32*d_2);
            atomicAdd(vj+(i0+5)+nao*(j0+0)+nao2, gout33*d_0+gout34*d_1+gout35*d_2);
            atomicAdd(vj+(i0+0)+nao*(j0+0)+2*nao2, gout36*d_0+gout37*d_1+gout38*d_2);
            atomicAdd(vj+(i0+1)+nao*(j0+0)+2*nao2, gout39*d_0+gout40*d_1+gout41*d_2);
            atomicAdd(vj+(i0+2)+nao*(j0+0)+2*nao2, gout42*d_0+gout43*d_1+gout44*d_2);
            atomicAdd(vj+(i0+3)+nao*(j0+0)+2*nao2, gout45*d_0+gout46*d_1+gout47*d_2);
            atomicAdd(vj+(i0+4)+nao*(j0+0)+2*nao2, gout48*d_0+gout49*d_1+gout50*d_2);
            atomicAdd(vj+(i0+5)+nao*(j0+0)+2*nao2, gout51*d_0+gout52*d_1+gout53*d_2);
            atomicAdd(vj+nao*(i0+0)+(j0+0), gout54*d_0+gout55*d_1+gout56*d_2);
            atomicAdd(vj+nao*(i0+1)+(j0+0), gout57*d_0+gout58*d_1+gout59*d_2);
            atomicAdd(vj+nao*(i0+2)+(j0+0), gout60*d_0+gout61*d_1+gout62*d_2);
            atomicAdd(vj+nao*(i0+3)+(j0+0), gout63*d_0+gout64*d_1+gout65*d_2);
            atomicAdd(vj+nao*(i0+4)+(j0+0), gout66*d_0+gout67*d_1+gout68*d_2);
            atomicAdd(vj+nao*(i0+5)+(j0+0), gout69*d_0+gout70*d_1+gout71*d_2);
            atomicAdd(vj+nao*(i0+0)+(j0+0)+nao2, gout72*d_0+gout73*d_1+gout74*d_2);
            atomicAdd(vj+nao*(i0+1)+(j0+0)+nao2, gout75*d_0+gout76*d_1+gout77*d_2);
            atomicAdd(vj+nao*(i0+2)+(j0+0)+nao2, gout78*d_0+gout79*d_1+gout80*d_2);
            atomicAdd(vj+nao*(i0+3)+(j0+0)+nao2, gout81*d_0+gout82*d_1+gout83*d_2);
            atomicAdd(vj+nao*(i0+4)+(j0+0)+nao2, gout84*d_0+gout85*d_1+gout86*d_2);
            atomicAdd(vj+nao*(i0+5)+(j0+0)+nao2, gout87*d_0+gout88*d_1+gout89*d_2);
            atomicAdd(vj+nao*(i0+0)+(j0+0)+2*nao2, gout90*d_0+gout91*d_1+gout92*d_2);
            atomicAdd(vj+nao*(i0+1)+(j0+0)+2*nao2, gout93*d_0+gout94*d_1+gout95*d_2);
            atomicAdd(vj+nao*(i0+2)+(j0+0)+2*nao2, gout96*d_0+gout97*d_1+gout98*d_2);
            atomicAdd(vj+nao*(i0+3)+(j0+0)+2*nao2, gout99*d_0+gout100*d_1+gout101*d_2);
            atomicAdd(vj+nao*(i0+4)+(j0+0)+2*nao2, gout102*d_0+gout103*d_1+gout104*d_2);
            atomicAdd(vj+nao*(i0+5)+(j0+0)+2*nao2, gout105*d_0+gout106*d_1+gout107*d_2);
            vj += 3*nao2;
        }
        if (vk != NULL) {
            // ijkl, jk -> il
            d_0 = dm[(j0+0)+nao*(k0+0)];
            d_1 = dm[(j0+0)+nao*(k0+1)];
            d_2 = dm[(j0+0)+nao*(k0+2)];
            atomicAdd(vk+(i0+0)+nao*(l0+0), gout0*d_0+gout1*d_1+gout2*d_2);
            atomicAdd(vk+(i0+1)+nao*(l0+0), gout3*d_0+gout4*d_1+gout5*d_2);
            atomicAdd(vk+(i0+2)+nao*(l0+0), gout6*d_0+gout7*d_1+gout8*d_2);
            atomicAdd(vk+(i0+3)+nao*(l0+0), gout9*d_0+gout10*d_1+gout11*d_2);
            atomicAdd(vk+(i0+4)+nao*(l0+0), gout12*d_0+gout13*d_1+gout14*d_2);
            atomicAdd(vk+(i0+5)+nao*(l0+0), gout15*d_0+gout16*d_1+gout17*d_2);
            atomicAdd(vk+(i0+0)+nao*(l0+0)+nao2, gout18*d_0+gout19*d_1+gout20*d_2);
            atomicAdd(vk+(i0+1)+nao*(l0+0)+nao2, gout21*d_0+gout22*d_1+gout23*d_2);
            atomicAdd(vk+(i0+2)+nao*(l0+0)+nao2, gout24*d_0+gout25*d_1+gout26*d_2);
            atomicAdd(vk+(i0+3)+nao*(l0+0)+nao2, gout27*d_0+gout28*d_1+gout29*d_2);
            atomicAdd(vk+(i0+4)+nao*(l0+0)+nao2, gout30*d_0+gout31*d_1+gout32*d_2);
            atomicAdd(vk+(i0+5)+nao*(l0+0)+nao2, gout33*d_0+gout34*d_1+gout35*d_2);
            atomicAdd(vk+(i0+0)+nao*(l0+0)+2*nao2, gout36*d_0+gout37*d_1+gout38*d_2);
            atomicAdd(vk+(i0+1)+nao*(l0+0)+2*nao2, gout39*d_0+gout40*d_1+gout41*d_2);
            atomicAdd(vk+(i0+2)+nao*(l0+0)+2*nao2, gout42*d_0+gout43*d_1+gout44*d_2);
            atomicAdd(vk+(i0+3)+nao*(l0+0)+2*nao2, gout45*d_0+gout46*d_1+gout47*d_2);
            atomicAdd(vk+(i0+4)+nao*(l0+0)+2*nao2, gout48*d_0+gout49*d_1+gout50*d_2);
            atomicAdd(vk+(i0+5)+nao*(l0+0)+2*nao2, gout51*d_0+gout52*d_1+gout53*d_2);
            // ijkl, jl -> ik
            d_0 = dm[(j0+0)+nao*(l0+0)];
            atomicAdd(vk+(i0+0)+nao*(k0+0), gout0*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+1), gout1*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+2), gout2*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+0), gout3*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+1), gout4*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+2), gout5*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+0), gout6*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+1), gout7*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+2), gout8*d_0);
            atomicAdd(vk+(i0+3)+nao*(k0+0), gout9*d_0);
            atomicAdd(vk+(i0+3)+nao*(k0+1), gout10*d_0);
            atomicAdd(vk+(i0+3)+nao*(k0+2), gout11*d_0);
            atomicAdd(vk+(i0+4)+nao*(k0+0), gout12*d_0);
            atomicAdd(vk+(i0+4)+nao*(k0+1), gout13*d_0);
            atomicAdd(vk+(i0+4)+nao*(k0+2), gout14*d_0);
            atomicAdd(vk+(i0+5)+nao*(k0+0), gout15*d_0);
            atomicAdd(vk+(i0+5)+nao*(k0+1), gout16*d_0);
            atomicAdd(vk+(i0+5)+nao*(k0+2), gout17*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+0)+nao2, gout18*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+1)+nao2, gout19*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+2)+nao2, gout20*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+0)+nao2, gout21*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+1)+nao2, gout22*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+2)+nao2, gout23*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+0)+nao2, gout24*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+1)+nao2, gout25*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+2)+nao2, gout26*d_0);
            atomicAdd(vk+(i0+3)+nao*(k0+0)+nao2, gout27*d_0);
            atomicAdd(vk+(i0+3)+nao*(k0+1)+nao2, gout28*d_0);
            atomicAdd(vk+(i0+3)+nao*(k0+2)+nao2, gout29*d_0);
            atomicAdd(vk+(i0+4)+nao*(k0+0)+nao2, gout30*d_0);
            atomicAdd(vk+(i0+4)+nao*(k0+1)+nao2, gout31*d_0);
            atomicAdd(vk+(i0+4)+nao*(k0+2)+nao2, gout32*d_0);
            atomicAdd(vk+(i0+5)+nao*(k0+0)+nao2, gout33*d_0);
            atomicAdd(vk+(i0+5)+nao*(k0+1)+nao2, gout34*d_0);
            atomicAdd(vk+(i0+5)+nao*(k0+2)+nao2, gout35*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+0)+2*nao2, gout36*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+1)+2*nao2, gout37*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+2)+2*nao2, gout38*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+0)+2*nao2, gout39*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+1)+2*nao2, gout40*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+2)+2*nao2, gout41*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+0)+2*nao2, gout42*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+1)+2*nao2, gout43*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+2)+2*nao2, gout44*d_0);
            atomicAdd(vk+(i0+3)+nao*(k0+0)+2*nao2, gout45*d_0);
            atomicAdd(vk+(i0+3)+nao*(k0+1)+2*nao2, gout46*d_0);
            atomicAdd(vk+(i0+3)+nao*(k0+2)+2*nao2, gout47*d_0);
            atomicAdd(vk+(i0+4)+nao*(k0+0)+2*nao2, gout48*d_0);
            atomicAdd(vk+(i0+4)+nao*(k0+1)+2*nao2, gout49*d_0);
            atomicAdd(vk+(i0+4)+nao*(k0+2)+2*nao2, gout50*d_0);
            atomicAdd(vk+(i0+5)+nao*(k0+0)+2*nao2, gout51*d_0);
            atomicAdd(vk+(i0+5)+nao*(k0+1)+2*nao2, gout52*d_0);
            atomicAdd(vk+(i0+5)+nao*(k0+2)+2*nao2, gout53*d_0);
            // ijkl, ik -> jl
            d_0 = dm[(i0+0)+nao*(k0+0)];
            d_1 = dm[(i0+0)+nao*(k0+1)];
            d_2 = dm[(i0+0)+nao*(k0+2)];
            d_3 = dm[(i0+1)+nao*(k0+0)];
            d_4 = dm[(i0+1)+nao*(k0+1)];
            d_5 = dm[(i0+1)+nao*(k0+2)];
            d_6 = dm[(i0+2)+nao*(k0+0)];
            d_7 = dm[(i0+2)+nao*(k0+1)];
            d_8 = dm[(i0+2)+nao*(k0+2)];
            d_9 = dm[(i0+3)+nao*(k0+0)];
            d_10 = dm[(i0+3)+nao*(k0+1)];
            d_11 = dm[(i0+3)+nao*(k0+2)];
            d_12 = dm[(i0+4)+nao*(k0+0)];
            d_13 = dm[(i0+4)+nao*(k0+1)];
            d_14 = dm[(i0+4)+nao*(k0+2)];
            d_15 = dm[(i0+5)+nao*(k0+0)];
            d_16 = dm[(i0+5)+nao*(k0+1)];
            d_17 = dm[(i0+5)+nao*(k0+2)];
            atomicAdd(vk+(j0+0)+nao*(l0+0), gout54*d_0+gout55*d_1+gout56*d_2+gout57*d_3+gout58*d_4+gout59*d_5+gout60*d_6+gout61*d_7+gout62*d_8+gout63*d_9+gout64*d_10+gout65*d_11+gout66*d_12+gout67*d_13+gout68*d_14+gout69*d_15+gout70*d_16+gout71*d_17);
            atomicAdd(vk+(j0+0)+nao*(l0+0)+nao2, gout72*d_0+gout73*d_1+gout74*d_2+gout75*d_3+gout76*d_4+gout77*d_5+gout78*d_6+gout79*d_7+gout80*d_8+gout81*d_9+gout82*d_10+gout83*d_11+gout84*d_12+gout85*d_13+gout86*d_14+gout87*d_15+gout88*d_16+gout89*d_17);
            atomicAdd(vk+(j0+0)+nao*(l0+0)+2*nao2, gout90*d_0+gout91*d_1+gout92*d_2+gout93*d_3+gout94*d_4+gout95*d_5+gout96*d_6+gout97*d_7+gout98*d_8+gout99*d_9+gout100*d_10+gout101*d_11+gout102*d_12+gout103*d_13+gout104*d_14+gout105*d_15+gout106*d_16+gout107*d_17);
            // ijkl, il -> jk
            d_0 = dm[(i0+0)+nao*(l0+0)];
            d_1 = dm[(i0+1)+nao*(l0+0)];
            d_2 = dm[(i0+2)+nao*(l0+0)];
            d_3 = dm[(i0+3)+nao*(l0+0)];
            d_4 = dm[(i0+4)+nao*(l0+0)];
            d_5 = dm[(i0+5)+nao*(l0+0)];
            atomicAdd(vk+(j0+0)+nao*(k0+0), gout54*d_0+gout57*d_1+gout60*d_2+gout63*d_3+gout66*d_4+gout69*d_5);
            atomicAdd(vk+(j0+0)+nao*(k0+1), gout55*d_0+gout58*d_1+gout61*d_2+gout64*d_3+gout67*d_4+gout70*d_5);
            atomicAdd(vk+(j0+0)+nao*(k0+2), gout56*d_0+gout59*d_1+gout62*d_2+gout65*d_3+gout68*d_4+gout71*d_5);
            atomicAdd(vk+(j0+0)+nao*(k0+0)+nao2, gout72*d_0+gout75*d_1+gout78*d_2+gout81*d_3+gout84*d_4+gout87*d_5);
            atomicAdd(vk+(j0+0)+nao*(k0+1)+nao2, gout73*d_0+gout76*d_1+gout79*d_2+gout82*d_3+gout85*d_4+gout88*d_5);
            atomicAdd(vk+(j0+0)+nao*(k0+2)+nao2, gout74*d_0+gout77*d_1+gout80*d_2+gout83*d_3+gout86*d_4+gout89*d_5);
            atomicAdd(vk+(j0+0)+nao*(k0+0)+2*nao2, gout90*d_0+gout93*d_1+gout96*d_2+gout99*d_3+gout102*d_4+gout105*d_5);
            atomicAdd(vk+(j0+0)+nao*(k0+1)+2*nao2, gout91*d_0+gout94*d_1+gout97*d_2+gout100*d_3+gout103*d_4+gout106*d_5);
            atomicAdd(vk+(j0+0)+nao*(k0+2)+2*nao2, gout92*d_0+gout95*d_1+gout98*d_2+gout101*d_3+gout104*d_4+gout107*d_5);
            vk += 3*nao2;
        }
        dm += nao2;
    }
}

__global__
static void GINTint2e_ip1_jk_kernel_2011(GINTEnvVars envs, JKMatrix jk,
                                    BasisProdOffsets offsets)
{
    int ntasks_ij = offsets.ntasks_ij;
    int ntasks_kl = offsets.ntasks_kl;
    int task_ij = blockIdx.x * blockDim.x + threadIdx.x;
    int task_kl = blockIdx.y * blockDim.y + threadIdx.y;
    if (task_ij >= ntasks_ij || task_kl >= ntasks_kl) {
        return;
    }
    int bas_ij = offsets.bas_ij + task_ij;
    int bas_kl = offsets.bas_kl + task_kl;
    double norm = envs.fac;
    double omega = envs.omega;
    int *bas_pair2bra = c_bpcache.bas_pair2bra;
    int *bas_pair2ket = c_bpcache.bas_pair2ket;
    int ish = bas_pair2bra[bas_ij];
    int jsh = bas_pair2ket[bas_ij];
    int ksh = bas_pair2bra[bas_kl];
    int lsh = bas_pair2ket[bas_kl];
    int nprim_ij = envs.nprim_ij;
    int nprim_kl = envs.nprim_kl;
    int prim_ij = offsets.primitive_ij + task_ij * nprim_ij;
    int prim_kl = offsets.primitive_kl + task_kl * nprim_kl;

    double* __restrict__ a12 = c_bpcache.a12;
    double* __restrict__ e12 = c_bpcache.e12;
    double* __restrict__ x12 = c_bpcache.x12;
    double* __restrict__ y12 = c_bpcache.y12;
    double* __restrict__ z12 = c_bpcache.z12;
    double * __restrict__ i_exponent = c_bpcache.a1;
    double * __restrict__ j_exponent = c_bpcache.a2;

    int ij, kl;
    int prim_ij0, prim_ij1, prim_kl0, prim_kl1;
    int nbas = c_bpcache.nbas;
    double* __restrict__ bas_x = c_bpcache.bas_coords;
    double* __restrict__ bas_y = bas_x + nbas;
    double* __restrict__ bas_z = bas_y + nbas;

    double gout0 = 0;
    double gout1 = 0;
    double gout2 = 0;
    double gout3 = 0;
    double gout4 = 0;
    double gout5 = 0;
    double gout6 = 0;
    double gout7 = 0;
    double gout8 = 0;
    double gout9 = 0;
    double gout10 = 0;
    double gout11 = 0;
    double gout12 = 0;
    double gout13 = 0;
    double gout14 = 0;
    double gout15 = 0;
    double gout16 = 0;
    double gout17 = 0;
    double gout18 = 0;
    double gout19 = 0;
    double gout20 = 0;
    double gout21 = 0;
    double gout22 = 0;
    double gout23 = 0;
    double gout24 = 0;
    double gout25 = 0;
    double gout26 = 0;
    double gout27 = 0;
    double gout28 = 0;
    double gout29 = 0;
    double gout30 = 0;
    double gout31 = 0;
    double gout32 = 0;
    double gout33 = 0;
    double gout34 = 0;
    double gout35 = 0;
    double gout36 = 0;
    double gout37 = 0;
    double gout38 = 0;
    double gout39 = 0;
    double gout40 = 0;
    double gout41 = 0;
    double gout42 = 0;
    double gout43 = 0;
    double gout44 = 0;
    double gout45 = 0;
    double gout46 = 0;
    double gout47 = 0;
    double gout48 = 0;
    double gout49 = 0;
    double gout50 = 0;
    double gout51 = 0;
    double gout52 = 0;
    double gout53 = 0;
    double gout54 = 0;
    double gout55 = 0;
    double gout56 = 0;
    double gout57 = 0;
    double gout58 = 0;
    double gout59 = 0;
    double gout60 = 0;
    double gout61 = 0;
    double gout62 = 0;
    double gout63 = 0;
    double gout64 = 0;
    double gout65 = 0;
    double gout66 = 0;
    double gout67 = 0;
    double gout68 = 0;
    double gout69 = 0;
    double gout70 = 0;
    double gout71 = 0;
    double gout72 = 0;
    double gout73 = 0;
    double gout74 = 0;
    double gout75 = 0;
    double gout76 = 0;
    double gout77 = 0;
    double gout78 = 0;
    double gout79 = 0;
    double gout80 = 0;
    double gout81 = 0;
    double gout82 = 0;
    double gout83 = 0;
    double gout84 = 0;
    double gout85 = 0;
    double gout86 = 0;
    double gout87 = 0;
    double gout88 = 0;
    double gout89 = 0;
    double gout90 = 0;
    double gout91 = 0;
    double gout92 = 0;
    double gout93 = 0;
    double gout94 = 0;
    double gout95 = 0;
    double gout96 = 0;
    double gout97 = 0;
    double gout98 = 0;
    double gout99 = 0;
    double gout100 = 0;
    double gout101 = 0;
    double gout102 = 0;
    double gout103 = 0;
    double gout104 = 0;
    double gout105 = 0;
    double gout106 = 0;
    double gout107 = 0;
    double gout108 = 0;
    double gout109 = 0;
    double gout110 = 0;
    double gout111 = 0;
    double gout112 = 0;
    double gout113 = 0;
    double gout114 = 0;
    double gout115 = 0;
    double gout116 = 0;
    double gout117 = 0;
    double gout118 = 0;
    double gout119 = 0;
    double gout120 = 0;
    double gout121 = 0;
    double gout122 = 0;
    double gout123 = 0;
    double gout124 = 0;
    double gout125 = 0;
    double gout126 = 0;
    double gout127 = 0;
    double gout128 = 0;
    double gout129 = 0;
    double gout130 = 0;
    double gout131 = 0;
    double gout132 = 0;
    double gout133 = 0;
    double gout134 = 0;
    double gout135 = 0;
    double gout136 = 0;
    double gout137 = 0;
    double gout138 = 0;
    double gout139 = 0;
    double gout140 = 0;
    double gout141 = 0;
    double gout142 = 0;
    double gout143 = 0;
    double gout144 = 0;
    double gout145 = 0;
    double gout146 = 0;
    double gout147 = 0;
    double gout148 = 0;
    double gout149 = 0;
    double gout150 = 0;
    double gout151 = 0;
    double gout152 = 0;
    double gout153 = 0;
    double gout154 = 0;
    double gout155 = 0;
    double gout156 = 0;
    double gout157 = 0;
    double gout158 = 0;
    double gout159 = 0;
    double gout160 = 0;
    double gout161 = 0;
    double gout162 = 0;
    double gout163 = 0;
    double gout164 = 0;
    double gout165 = 0;
    double gout166 = 0;
    double gout167 = 0;
    double gout168 = 0;
    double gout169 = 0;
    double gout170 = 0;
    double gout171 = 0;
    double gout172 = 0;
    double gout173 = 0;
    double gout174 = 0;
    double gout175 = 0;
    double gout176 = 0;
    double gout177 = 0;
    double gout178 = 0;
    double gout179 = 0;
    double gout180 = 0;
    double gout181 = 0;
    double gout182 = 0;
    double gout183 = 0;
    double gout184 = 0;
    double gout185 = 0;
    double gout186 = 0;
    double gout187 = 0;
    double gout188 = 0;
    double gout189 = 0;
    double gout190 = 0;
    double gout191 = 0;
    double gout192 = 0;
    double gout193 = 0;
    double gout194 = 0;
    double gout195 = 0;
    double gout196 = 0;
    double gout197 = 0;
    double gout198 = 0;
    double gout199 = 0;
    double gout200 = 0;
    double gout201 = 0;
    double gout202 = 0;
    double gout203 = 0;
    double gout204 = 0;
    double gout205 = 0;
    double gout206 = 0;
    double gout207 = 0;
    double gout208 = 0;
    double gout209 = 0;
    double gout210 = 0;
    double gout211 = 0;
    double gout212 = 0;
    double gout213 = 0;
    double gout214 = 0;
    double gout215 = 0;
    double gout216 = 0;
    double gout217 = 0;
    double gout218 = 0;
    double gout219 = 0;
    double gout220 = 0;
    double gout221 = 0;
    double gout222 = 0;
    double gout223 = 0;
    double gout224 = 0;
    double gout225 = 0;
    double gout226 = 0;
    double gout227 = 0;
    double gout228 = 0;
    double gout229 = 0;
    double gout230 = 0;
    double gout231 = 0;
    double gout232 = 0;
    double gout233 = 0;
    double gout234 = 0;
    double gout235 = 0;
    double gout236 = 0;
    double gout237 = 0;
    double gout238 = 0;
    double gout239 = 0;
    double gout240 = 0;
    double gout241 = 0;
    double gout242 = 0;
    double gout243 = 0;
    double gout244 = 0;
    double gout245 = 0;
    double gout246 = 0;
    double gout247 = 0;
    double gout248 = 0;
    double gout249 = 0;
    double gout250 = 0;
    double gout251 = 0;
    double gout252 = 0;
    double gout253 = 0;
    double gout254 = 0;
    double gout255 = 0;
    double gout256 = 0;
    double gout257 = 0;
    double gout258 = 0;
    double gout259 = 0;
    double gout260 = 0;
    double gout261 = 0;
    double gout262 = 0;
    double gout263 = 0;
    double gout264 = 0;
    double gout265 = 0;
    double gout266 = 0;
    double gout267 = 0;
    double gout268 = 0;
    double gout269 = 0;
    double gout270 = 0;
    double gout271 = 0;
    double gout272 = 0;
    double gout273 = 0;
    double gout274 = 0;
    double gout275 = 0;
    double gout276 = 0;
    double gout277 = 0;
    double gout278 = 0;
    double gout279 = 0;
    double gout280 = 0;
    double gout281 = 0;
    double gout282 = 0;
    double gout283 = 0;
    double gout284 = 0;
    double gout285 = 0;
    double gout286 = 0;
    double gout287 = 0;
    double gout288 = 0;
    double gout289 = 0;
    double gout290 = 0;
    double gout291 = 0;
    double gout292 = 0;
    double gout293 = 0;
    double gout294 = 0;
    double gout295 = 0;
    double gout296 = 0;
    double gout297 = 0;
    double gout298 = 0;
    double gout299 = 0;
    double gout300 = 0;
    double gout301 = 0;
    double gout302 = 0;
    double gout303 = 0;
    double gout304 = 0;
    double gout305 = 0;
    double gout306 = 0;
    double gout307 = 0;
    double gout308 = 0;
    double gout309 = 0;
    double gout310 = 0;
    double gout311 = 0;
    double gout312 = 0;
    double gout313 = 0;
    double gout314 = 0;
    double gout315 = 0;
    double gout316 = 0;
    double gout317 = 0;
    double gout318 = 0;
    double gout319 = 0;
    double gout320 = 0;
    double gout321 = 0;
    double gout322 = 0;
    double gout323 = 0;

    double xi = bas_x[ish];
    double yi = bas_y[ish];
    double zi = bas_z[ish];
    double ABx = xi - bas_x[jsh];
    double ABy = yi - bas_y[jsh];
    double ABz = zi - bas_z[jsh];
    double xk = bas_x[ksh];
    double yk = bas_y[ksh];
    double zk = bas_z[ksh];
    double CDx = xk - bas_x[lsh];
    double CDy = yk - bas_y[lsh];
    double CDz = zk - bas_z[lsh];
    prim_ij0 = prim_ij;
    prim_ij1 = prim_ij + nprim_ij;
    prim_kl0 = prim_kl;
    prim_kl1 = prim_kl + nprim_kl;
    double rw[6];
    int irys;
    for (ij = prim_ij0; ij < prim_ij1; ++ij) {
        double alpha = i_exponent[ij];
        double beta = j_exponent[ij];
        double aij = a12[ij];
        double eij = e12[ij];
        double xij = x12[ij];
        double yij = y12[ij];
        double zij = z12[ij];
    for (kl = prim_kl0; kl < prim_kl1; ++kl) {
        double akl = a12[kl];
        double ekl = e12[kl];
        double xkl = x12[kl];
        double ykl = y12[kl];
        double zkl = z12[kl];
        double xijxkl = xij - xkl;
        double yijykl = yij - ykl;
        double zijzkl = zij - zkl;
        double aijkl = aij + akl;
        double a1 = aij * akl;
        double a0 = a1 / aijkl;
        double theta = omega > 0.0 ? omega * omega / (omega * omega + a0) : 1.0; 
        a0 *= theta;
        double x = a0 * (xijxkl * xijxkl + yijykl * yijykl + zijzkl * zijzkl);
        double fac = norm * eij * ekl * sqrt(a0 / (a1 * a1 * a1));
        //double fac = norm * eij * ekl / (sqrt(aijkl) * a1);

        GINTrys_root<3>(x, rw);
        GINTscale_u<3>(rw, theta);
      for (irys = 0; irys < 3; ++irys) {
            double weight0 = rw[irys+3] * fac;
            double root0 = rw[irys];
            double u2 = a0 * root0;
            double tmp4 = .5 / (u2 * aijkl + a1);
            double B00 = u2 * tmp4;
            double tmp1 = 2 * B00;
            double B10 = B00 + tmp4 * akl;
            double tmp2 = tmp1 * akl;
            double C00x = xij - xi - tmp2 * xijxkl;
            double C00y = yij - yi - tmp2 * yijykl;
            double C00z = zij - zi - tmp2 * zijzkl;
            double B01 = B00 + tmp4 * aij;
            double tmp3 = tmp1 * aij;
            double D00x = xkl - xk + tmp3 * xijxkl;
            double D00y = ykl - yk + tmp3 * yijykl;
            double D00z = zkl - zk + tmp3 * zijzkl;

            double g0 = B10+C00x*C00x;
            double g1 = 3*B10*C00x;
            double g2 = g1+C00x*C00x*C00x;
            double g3 = C00x*D00x;
            double g4 = B00+g3;
            double g5 = 2*B00*C00x;
            double g6 = g0*D00x;
            double g7 = g5+g6;
            double g8 = 3*B00*g0;
            double g9 = 3*B10;
            double g10 = g9+C00x*C00x;
            double g11 = C00x*g10*D00x;
            double g12 = g8+g11;
            double g13 = ABx+C00x;
            double g14 = C00x*g13;
            double g15 = B10+g14;
            double g16 = ABx*g0;
            double g17 = g1+C00x*C00x*C00x+g16;
            double g18 = g13*D00x;
            double g19 = B00+g18;
            double g20 = 2*C00x;
            double g21 = ABx+g20;
            double g24 = (B00*g21)+(g15*D00x);
            double g30 = B00*(g9+(C00x*((2*ABx)+(3*C00x))));
            double g32 = g30+(g17*D00x);
            double g33 = CDx+D00x;
            double g35 = B00+(C00x*g33);
            double g36 = g0*g33;
            double g37 = g5+g36;
            double g39 = g8+(C00x*g10*g33);
            double g41 = B01+(D00x*g33);
            double g45 = CDx+(2*D00x);
            double g46 = B00*g45;
            double g47 = (B01*C00x)+(C00x*D00x*g33)+g46;
            double g48 = 2*B00*B00;
            double g51 = g48+(2*B00*C00x*g45)+(g0*g41);
            double g52 = 6*B00*B00*C00x;
            double g53 = 3*B00*g0*g45;
            double g54 = C00x*g10*g41;
            double g55 = g52+g53+g54;
            double g57 = B00+(g13*g33);
            double g59 = g5+g36+(ABx*g35);
            double g61 = g30+(g17*g33);
            double g63 = g46+(g13*g41);
            double g66 = g48+(B00*g21*g45)+(g15*g41);
            double g68 = g52+g53+g54+(ABx*g51);
            double g69 = B10+C00y*C00y;
            double g70 = 3*B10*C00y;
            double g71 = g70+C00y*C00y*C00y;
            double g73 = B00+(C00y*D00y);
            double g74 = 2*B00*C00y;
            double g76 = g74+(g69*D00y);
            double g77 = 3*B00*g69;
            double g78 = g9+C00y*C00y;
            double g80 = g77+(C00y*g78*D00y);
            double g81 = ABy+C00y;
            double g83 = B10+(C00y*g81);
            double g85 = g70+C00y*C00y*C00y+(ABy*g69);
            double g87 = B00+(g81*D00y);
            double g89 = ABy+(2*C00y);
            double g92 = (B00*g89)+(g83*D00y);
            double g98 = B00*(g9+(C00y*((2*ABy)+(3*C00y))));
            double g100 = g98+(g85*D00y);
            double g101 = CDy+D00y;
            double g103 = B00+(C00y*g101);
            double g104 = g69*g101;
            double g105 = g74+g104;
            double g107 = g77+(C00y*g78*g101);
            double g109 = B01+(D00y*g101);
            double g113 = CDy+(2*D00y);
            double g114 = B00*g113;
            double g115 = (B01*C00y)+(C00y*D00y*g101)+g114;
            double g118 = g48+(2*B00*C00y*g113)+(g69*g109);
            double g119 = 6*B00*B00*C00y;
            double g120 = 3*B00*g69*g113;
            double g121 = C00y*g78*g109;
            double g122 = g119+g120+g121;
            double g124 = B00+(g81*g101);
            double g126 = g74+g104+(ABy*g103);
            double g128 = g98+(g85*g101);
            double g130 = g114+(g81*g109);
            double g133 = g48+(B00*g89*g113)+(g83*g109);
            double g135 = g119+g120+g121+(ABy*g118);
            double g136 = B10+C00z*C00z;
            double g137 = 3*B10*C00z;
            double g138 = g137+C00z*C00z*C00z;
            double g140 = B00+(C00z*D00z);
            double g141 = 2*B00*C00z;
            double g143 = g141+(g136*D00z);
            double g144 = 3*B00*g136;
            double g145 = g9+C00z*C00z;
            double g147 = g144+(C00z*g145*D00z);
            double g148 = ABz+C00z;
            double g150 = B10+(C00z*g148);
            double g152 = g137+C00z*C00z*C00z+(ABz*g136);
            double g154 = B00+(g148*D00z);
            double g156 = ABz+(2*C00z);
            double g159 = (B00*g156)+(g150*D00z);
            double g165 = B00*(g9+(C00z*((2*ABz)+(3*C00z))));
            double g167 = g165+(g152*D00z);
            double g168 = CDz+D00z;
            double g170 = B00+(C00z*g168);
            double g171 = g136*g168;
            double g172 = g141+g171;
            double g174 = g144+(C00z*g145*g168);
            double g176 = B01+(D00z*g168);
            double g180 = CDz+(2*D00z);
            double g181 = B00*g180;
            double g182 = (B01*C00z)+(C00z*D00z*g168)+g181;
            double g185 = g48+(2*B00*C00z*g180)+(g136*g176);
            double g186 = 6*B00*B00*C00z;
            double g187 = 3*B00*g136*g180;
            double g188 = C00z*g145*g176;
            double g189 = g186+g187+g188;
            double g191 = B00+(g148*g168);
            double g193 = g141+g171+(ABz*g170);
            double g195 = g165+(g152*g168);
            double g197 = g181+(g148*g176);
            double g200 = g48+(B00*g156*g180)+(g150*g176);
            double g202 = g186+g187+g188+(ABz*g185);

            gout0 += (-2*g47 + 2*alpha*g55) * weight0;
            gout1 += (-2*g4 + 2*alpha*g12) * (g101) * weight0;
            gout2 += (-2*g4 + 2*alpha*g12) * (g168) * weight0;
            gout3 += (-2*g35 + 2*alpha*g39) * (D00y) * weight0;
            gout4 += (-2*C00x + 2*alpha*g2) * (g109) * weight0;
            gout5 += (-2*C00x + 2*alpha*g2) * (D00y) * (g168) * weight0;
            gout6 += (-2*g35 + 2*alpha*g39) * (D00z) * weight0;
            gout7 += (-2*C00x + 2*alpha*g2) * (g101) * (D00z) * weight0;
            gout8 += (-2*C00x + 2*alpha*g2) * (g176) * weight0;
            gout9 += (-g41 + 2*alpha*g51) * (C00y) * weight0;
            gout10 += (-D00x + 2*alpha*g7) * (g103) * weight0;
            gout11 += (-D00x + 2*alpha*g7) * (C00y) * (g168) * weight0;
            gout12 += (-g33 + 2*alpha*g37) * (g73) * weight0;
            gout13 += (-1 + 2*alpha*g0) * (g115) * weight0;
            gout14 += (-1 + 2*alpha*g0) * (g73) * (g168) * weight0;
            gout15 += (-g33 + 2*alpha*g37) * (C00y) * (D00z) * weight0;
            gout16 += (-1 + 2*alpha*g0) * (g103) * (D00z) * weight0;
            gout17 += (-1 + 2*alpha*g0) * (C00y) * (g176) * weight0;
            gout18 += (-g41 + 2*alpha*g51) * (C00z) * weight0;
            gout19 += (-D00x + 2*alpha*g7) * (g101) * (C00z) * weight0;
            gout20 += (-D00x + 2*alpha*g7) * (g170) * weight0;
            gout21 += (-g33 + 2*alpha*g37) * (D00y) * (C00z) * weight0;
            gout22 += (-1 + 2*alpha*g0) * (g109) * (C00z) * weight0;
            gout23 += (-1 + 2*alpha*g0) * (D00y) * (g170) * weight0;
            gout24 += (-g33 + 2*alpha*g37) * (g140) * weight0;
            gout25 += (-1 + 2*alpha*g0) * (g101) * (g140) * weight0;
            gout26 += (-1 + 2*alpha*g0) * (g182) * weight0;
            gout27 += (2*alpha*g47) * (g69) * weight0;
            gout28 += (2*alpha*g4) * (g105) * weight0;
            gout29 += (2*alpha*g4) * (g69) * (g168) * weight0;
            gout30 += (2*alpha*g35) * (g76) * weight0;
            gout31 += (2*alpha*C00x) * (g118) * weight0;
            gout32 += (2*alpha*C00x) * (g76) * (g168) * weight0;
            gout33 += (2*alpha*g35) * (g69) * (D00z) * weight0;
            gout34 += (2*alpha*C00x) * (g105) * (D00z) * weight0;
            gout35 += (2*alpha*C00x) * (g69) * (g176) * weight0;
            gout36 += (2*alpha*g47) * (C00y) * (C00z) * weight0;
            gout37 += (2*alpha*g4) * (g103) * (C00z) * weight0;
            gout38 += (2*alpha*g4) * (C00y) * (g170) * weight0;
            gout39 += (2*alpha*g35) * (g73) * (C00z) * weight0;
            gout40 += (2*alpha*C00x) * (g115) * (C00z) * weight0;
            gout41 += (2*alpha*C00x) * (g73) * (g170) * weight0;
            gout42 += (2*alpha*g35) * (C00y) * (g140) * weight0;
            gout43 += (2*alpha*C00x) * (g103) * (g140) * weight0;
            gout44 += (2*alpha*C00x) * (C00y) * (g182) * weight0;
            gout45 += (2*alpha*g47) * (g136) * weight0;
            gout46 += (2*alpha*g4) * (g101) * (g136) * weight0;
            gout47 += (2*alpha*g4) * (g172) * weight0;
            gout48 += (2*alpha*g35) * (D00y) * (g136) * weight0;
            gout49 += (2*alpha*C00x) * (g109) * (g136) * weight0;
            gout50 += (2*alpha*C00x) * (D00y) * (g172) * weight0;
            gout51 += (2*alpha*g35) * (g143) * weight0;
            gout52 += (2*alpha*C00x) * (g101) * (g143) * weight0;
            gout53 += (2*alpha*C00x) * (g185) * weight0;
            gout54 += (g51) * (2*alpha*C00y) * weight0;
            gout55 += (g7) * (2*alpha*g103) * weight0;
            gout56 += (g7) * (2*alpha*C00y) * (g168) * weight0;
            gout57 += (g37) * (2*alpha*g73) * weight0;
            gout58 += (g0) * (2*alpha*g115) * weight0;
            gout59 += (g0) * (2*alpha*g73) * (g168) * weight0;
            gout60 += (g37) * (2*alpha*C00y) * (D00z) * weight0;
            gout61 += (g0) * (2*alpha*g103) * (D00z) * weight0;
            gout62 += (g0) * (2*alpha*C00y) * (g176) * weight0;
            gout63 += (g47) * (-1 + 2*alpha*g69) * weight0;
            gout64 += (g4) * (-g101 + 2*alpha*g105) * weight0;
            gout65 += (g4) * (-1 + 2*alpha*g69) * (g168) * weight0;
            gout66 += (g35) * (-D00y + 2*alpha*g76) * weight0;
            gout67 += (C00x) * (-g109 + 2*alpha*g118) * weight0;
            gout68 += (C00x) * (-D00y + 2*alpha*g76) * (g168) * weight0;
            gout69 += (g35) * (-1 + 2*alpha*g69) * (D00z) * weight0;
            gout70 += (C00x) * (-g101 + 2*alpha*g105) * (D00z) * weight0;
            gout71 += (C00x) * (-1 + 2*alpha*g69) * (g176) * weight0;
            gout72 += (g47) * (2*alpha*C00y) * (C00z) * weight0;
            gout73 += (g4) * (2*alpha*g103) * (C00z) * weight0;
            gout74 += (g4) * (2*alpha*C00y) * (g170) * weight0;
            gout75 += (g35) * (2*alpha*g73) * (C00z) * weight0;
            gout76 += (C00x) * (2*alpha*g115) * (C00z) * weight0;
            gout77 += (C00x) * (2*alpha*g73) * (g170) * weight0;
            gout78 += (g35) * (2*alpha*C00y) * (g140) * weight0;
            gout79 += (C00x) * (2*alpha*g103) * (g140) * weight0;
            gout80 += (C00x) * (2*alpha*C00y) * (g182) * weight0;
            gout81 += (g41) * (-2*C00y + 2*alpha*g71) * weight0;
            gout82 += (D00x) * (-2*g103 + 2*alpha*g107) * weight0;
            gout83 += (D00x) * (-2*C00y + 2*alpha*g71) * (g168) * weight0;
            gout84 += (g33) * (-2*g73 + 2*alpha*g80) * weight0;
            gout85 += (-2*g115 + 2*alpha*g122) * weight0;
            gout86 += (-2*g73 + 2*alpha*g80) * (g168) * weight0;
            gout87 += (g33) * (-2*C00y + 2*alpha*g71) * (D00z) * weight0;
            gout88 += (-2*g103 + 2*alpha*g107) * (D00z) * weight0;
            gout89 += (-2*C00y + 2*alpha*g71) * (g176) * weight0;
            gout90 += (g41) * (-1 + 2*alpha*g69) * (C00z) * weight0;
            gout91 += (D00x) * (-g101 + 2*alpha*g105) * (C00z) * weight0;
            gout92 += (D00x) * (-1 + 2*alpha*g69) * (g170) * weight0;
            gout93 += (g33) * (-D00y + 2*alpha*g76) * (C00z) * weight0;
            gout94 += (-g109 + 2*alpha*g118) * (C00z) * weight0;
            gout95 += (-D00y + 2*alpha*g76) * (g170) * weight0;
            gout96 += (g33) * (-1 + 2*alpha*g69) * (g140) * weight0;
            gout97 += (-g101 + 2*alpha*g105) * (g140) * weight0;
            gout98 += (-1 + 2*alpha*g69) * (g182) * weight0;
            gout99 += (g41) * (2*alpha*C00y) * (g136) * weight0;
            gout100 += (D00x) * (2*alpha*g103) * (g136) * weight0;
            gout101 += (D00x) * (2*alpha*C00y) * (g172) * weight0;
            gout102 += (g33) * (2*alpha*g73) * (g136) * weight0;
            gout103 += (2*alpha*g115) * (g136) * weight0;
            gout104 += (2*alpha*g73) * (g172) * weight0;
            gout105 += (g33) * (2*alpha*C00y) * (g143) * weight0;
            gout106 += (2*alpha*g103) * (g143) * weight0;
            gout107 += (2*alpha*C00y) * (g185) * weight0;
            gout108 += (g51) * (2*alpha*C00z) * weight0;
            gout109 += (g7) * (g101) * (2*alpha*C00z) * weight0;
            gout110 += (g7) * (2*alpha*g170) * weight0;
            gout111 += (g37) * (D00y) * (2*alpha*C00z) * weight0;
            gout112 += (g0) * (g109) * (2*alpha*C00z) * weight0;
            gout113 += (g0) * (D00y) * (2*alpha*g170) * weight0;
            gout114 += (g37) * (2*alpha*g140) * weight0;
            gout115 += (g0) * (g101) * (2*alpha*g140) * weight0;
            gout116 += (g0) * (2*alpha*g182) * weight0;
            gout117 += (g47) * (C00y) * (2*alpha*C00z) * weight0;
            gout118 += (g4) * (g103) * (2*alpha*C00z) * weight0;
            gout119 += (g4) * (C00y) * (2*alpha*g170) * weight0;
            gout120 += (g35) * (g73) * (2*alpha*C00z) * weight0;
            gout121 += (C00x) * (g115) * (2*alpha*C00z) * weight0;
            gout122 += (C00x) * (g73) * (2*alpha*g170) * weight0;
            gout123 += (g35) * (C00y) * (2*alpha*g140) * weight0;
            gout124 += (C00x) * (g103) * (2*alpha*g140) * weight0;
            gout125 += (C00x) * (C00y) * (2*alpha*g182) * weight0;
            gout126 += (g47) * (-1 + 2*alpha*g136) * weight0;
            gout127 += (g4) * (g101) * (-1 + 2*alpha*g136) * weight0;
            gout128 += (g4) * (-g168 + 2*alpha*g172) * weight0;
            gout129 += (g35) * (D00y) * (-1 + 2*alpha*g136) * weight0;
            gout130 += (C00x) * (g109) * (-1 + 2*alpha*g136) * weight0;
            gout131 += (C00x) * (D00y) * (-g168 + 2*alpha*g172) * weight0;
            gout132 += (g35) * (-D00z + 2*alpha*g143) * weight0;
            gout133 += (C00x) * (g101) * (-D00z + 2*alpha*g143) * weight0;
            gout134 += (C00x) * (-g176 + 2*alpha*g185) * weight0;
            gout135 += (g41) * (g69) * (2*alpha*C00z) * weight0;
            gout136 += (D00x) * (g105) * (2*alpha*C00z) * weight0;
            gout137 += (D00x) * (g69) * (2*alpha*g170) * weight0;
            gout138 += (g33) * (g76) * (2*alpha*C00z) * weight0;
            gout139 += (g118) * (2*alpha*C00z) * weight0;
            gout140 += (g76) * (2*alpha*g170) * weight0;
            gout141 += (g33) * (g69) * (2*alpha*g140) * weight0;
            gout142 += (g105) * (2*alpha*g140) * weight0;
            gout143 += (g69) * (2*alpha*g182) * weight0;
            gout144 += (g41) * (C00y) * (-1 + 2*alpha*g136) * weight0;
            gout145 += (D00x) * (g103) * (-1 + 2*alpha*g136) * weight0;
            gout146 += (D00x) * (C00y) * (-g168 + 2*alpha*g172) * weight0;
            gout147 += (g33) * (g73) * (-1 + 2*alpha*g136) * weight0;
            gout148 += (g115) * (-1 + 2*alpha*g136) * weight0;
            gout149 += (g73) * (-g168 + 2*alpha*g172) * weight0;
            gout150 += (g33) * (C00y) * (-D00z + 2*alpha*g143) * weight0;
            gout151 += (g103) * (-D00z + 2*alpha*g143) * weight0;
            gout152 += (C00y) * (-g176 + 2*alpha*g185) * weight0;
            gout153 += (g41) * (-2*C00z + 2*alpha*g138) * weight0;
            gout154 += (D00x) * (g101) * (-2*C00z + 2*alpha*g138) * weight0;
            gout155 += (D00x) * (-2*g170 + 2*alpha*g174) * weight0;
            gout156 += (g33) * (D00y) * (-2*C00z + 2*alpha*g138) * weight0;
            gout157 += (g109) * (-2*C00z + 2*alpha*g138) * weight0;
            gout158 += (D00y) * (-2*g170 + 2*alpha*g174) * weight0;
            gout159 += (g33) * (-2*g140 + 2*alpha*g147) * weight0;
            gout160 += (g101) * (-2*g140 + 2*alpha*g147) * weight0;
            gout161 += (-2*g182 + 2*alpha*g189) * weight0;
            gout162 += (2*beta*g68) * weight0;
            gout163 += (2*beta*g32) * (g101) * weight0;
            gout164 += (2*beta*g32) * (g168) * weight0;
            gout165 += (2*beta*g61) * (D00y) * weight0;
            gout166 += (2*beta*g17) * (g109) * weight0;
            gout167 += (2*beta*g17) * (D00y) * (g168) * weight0;
            gout168 += (2*beta*g61) * (D00z) * weight0;
            gout169 += (2*beta*g17) * (g101) * (D00z) * weight0;
            gout170 += (2*beta*g17) * (g176) * weight0;
            gout171 += (2*beta*g66) * (C00y) * weight0;
            gout172 += (2*beta*g24) * (g103) * weight0;
            gout173 += (2*beta*g24) * (C00y) * (g168) * weight0;
            gout174 += (2*beta*g59) * (g73) * weight0;
            gout175 += (2*beta*g15) * (g115) * weight0;
            gout176 += (2*beta*g15) * (g73) * (g168) * weight0;
            gout177 += (2*beta*g59) * (C00y) * (D00z) * weight0;
            gout178 += (2*beta*g15) * (g103) * (D00z) * weight0;
            gout179 += (2*beta*g15) * (C00y) * (g176) * weight0;
            gout180 += (2*beta*g66) * (C00z) * weight0;
            gout181 += (2*beta*g24) * (g101) * (C00z) * weight0;
            gout182 += (2*beta*g24) * (g170) * weight0;
            gout183 += (2*beta*g59) * (D00y) * (C00z) * weight0;
            gout184 += (2*beta*g15) * (g109) * (C00z) * weight0;
            gout185 += (2*beta*g15) * (D00y) * (g170) * weight0;
            gout186 += (2*beta*g59) * (g140) * weight0;
            gout187 += (2*beta*g15) * (g101) * (g140) * weight0;
            gout188 += (2*beta*g15) * (g182) * weight0;
            gout189 += (2*beta*g63) * (g69) * weight0;
            gout190 += (2*beta*g19) * (g105) * weight0;
            gout191 += (2*beta*g19) * (g69) * (g168) * weight0;
            gout192 += (2*beta*g57) * (g76) * weight0;
            gout193 += (2*beta*g13) * (g118) * weight0;
            gout194 += (2*beta*g13) * (g76) * (g168) * weight0;
            gout195 += (2*beta*g57) * (g69) * (D00z) * weight0;
            gout196 += (2*beta*g13) * (g105) * (D00z) * weight0;
            gout197 += (2*beta*g13) * (g69) * (g176) * weight0;
            gout198 += (2*beta*g63) * (C00y) * (C00z) * weight0;
            gout199 += (2*beta*g19) * (g103) * (C00z) * weight0;
            gout200 += (2*beta*g19) * (C00y) * (g170) * weight0;
            gout201 += (2*beta*g57) * (g73) * (C00z) * weight0;
            gout202 += (2*beta*g13) * (g115) * (C00z) * weight0;
            gout203 += (2*beta*g13) * (g73) * (g170) * weight0;
            gout204 += (2*beta*g57) * (C00y) * (g140) * weight0;
            gout205 += (2*beta*g13) * (g103) * (g140) * weight0;
            gout206 += (2*beta*g13) * (C00y) * (g182) * weight0;
            gout207 += (2*beta*g63) * (g136) * weight0;
            gout208 += (2*beta*g19) * (g101) * (g136) * weight0;
            gout209 += (2*beta*g19) * (g172) * weight0;
            gout210 += (2*beta*g57) * (D00y) * (g136) * weight0;
            gout211 += (2*beta*g13) * (g109) * (g136) * weight0;
            gout212 += (2*beta*g13) * (D00y) * (g172) * weight0;
            gout213 += (2*beta*g57) * (g143) * weight0;
            gout214 += (2*beta*g13) * (g101) * (g143) * weight0;
            gout215 += (2*beta*g13) * (g185) * weight0;
            gout216 += (g51) * (2*beta*g81) * weight0;
            gout217 += (g7) * (2*beta*g124) * weight0;
            gout218 += (g7) * (2*beta*g81) * (g168) * weight0;
            gout219 += (g37) * (2*beta*g87) * weight0;
            gout220 += (g0) * (2*beta*g130) * weight0;
            gout221 += (g0) * (2*beta*g87) * (g168) * weight0;
            gout222 += (g37) * (2*beta*g81) * (D00z) * weight0;
            gout223 += (g0) * (2*beta*g124) * (D00z) * weight0;
            gout224 += (g0) * (2*beta*g81) * (g176) * weight0;
            gout225 += (g47) * (2*beta*g83) * weight0;
            gout226 += (g4) * (2*beta*g126) * weight0;
            gout227 += (g4) * (2*beta*g83) * (g168) * weight0;
            gout228 += (g35) * (2*beta*g92) * weight0;
            gout229 += (C00x) * (2*beta*g133) * weight0;
            gout230 += (C00x) * (2*beta*g92) * (g168) * weight0;
            gout231 += (g35) * (2*beta*g83) * (D00z) * weight0;
            gout232 += (C00x) * (2*beta*g126) * (D00z) * weight0;
            gout233 += (C00x) * (2*beta*g83) * (g176) * weight0;
            gout234 += (g47) * (2*beta*g81) * (C00z) * weight0;
            gout235 += (g4) * (2*beta*g124) * (C00z) * weight0;
            gout236 += (g4) * (2*beta*g81) * (g170) * weight0;
            gout237 += (g35) * (2*beta*g87) * (C00z) * weight0;
            gout238 += (C00x) * (2*beta*g130) * (C00z) * weight0;
            gout239 += (C00x) * (2*beta*g87) * (g170) * weight0;
            gout240 += (g35) * (2*beta*g81) * (g140) * weight0;
            gout241 += (C00x) * (2*beta*g124) * (g140) * weight0;
            gout242 += (C00x) * (2*beta*g81) * (g182) * weight0;
            gout243 += (g41) * (2*beta*g85) * weight0;
            gout244 += (D00x) * (2*beta*g128) * weight0;
            gout245 += (D00x) * (2*beta*g85) * (g168) * weight0;
            gout246 += (g33) * (2*beta*g100) * weight0;
            gout247 += (2*beta*g135) * weight0;
            gout248 += (2*beta*g100) * (g168) * weight0;
            gout249 += (g33) * (2*beta*g85) * (D00z) * weight0;
            gout250 += (2*beta*g128) * (D00z) * weight0;
            gout251 += (2*beta*g85) * (g176) * weight0;
            gout252 += (g41) * (2*beta*g83) * (C00z) * weight0;
            gout253 += (D00x) * (2*beta*g126) * (C00z) * weight0;
            gout254 += (D00x) * (2*beta*g83) * (g170) * weight0;
            gout255 += (g33) * (2*beta*g92) * (C00z) * weight0;
            gout256 += (2*beta*g133) * (C00z) * weight0;
            gout257 += (2*beta*g92) * (g170) * weight0;
            gout258 += (g33) * (2*beta*g83) * (g140) * weight0;
            gout259 += (2*beta*g126) * (g140) * weight0;
            gout260 += (2*beta*g83) * (g182) * weight0;
            gout261 += (g41) * (2*beta*g81) * (g136) * weight0;
            gout262 += (D00x) * (2*beta*g124) * (g136) * weight0;
            gout263 += (D00x) * (2*beta*g81) * (g172) * weight0;
            gout264 += (g33) * (2*beta*g87) * (g136) * weight0;
            gout265 += (2*beta*g130) * (g136) * weight0;
            gout266 += (2*beta*g87) * (g172) * weight0;
            gout267 += (g33) * (2*beta*g81) * (g143) * weight0;
            gout268 += (2*beta*g124) * (g143) * weight0;
            gout269 += (2*beta*g81) * (g185) * weight0;
            gout270 += (g51) * (2*beta*g148) * weight0;
            gout271 += (g7) * (g101) * (2*beta*g148) * weight0;
            gout272 += (g7) * (2*beta*g191) * weight0;
            gout273 += (g37) * (D00y) * (2*beta*g148) * weight0;
            gout274 += (g0) * (g109) * (2*beta*g148) * weight0;
            gout275 += (g0) * (D00y) * (2*beta*g191) * weight0;
            gout276 += (g37) * (2*beta*g154) * weight0;
            gout277 += (g0) * (g101) * (2*beta*g154) * weight0;
            gout278 += (g0) * (2*beta*g197) * weight0;
            gout279 += (g47) * (C00y) * (2*beta*g148) * weight0;
            gout280 += (g4) * (g103) * (2*beta*g148) * weight0;
            gout281 += (g4) * (C00y) * (2*beta*g191) * weight0;
            gout282 += (g35) * (g73) * (2*beta*g148) * weight0;
            gout283 += (C00x) * (g115) * (2*beta*g148) * weight0;
            gout284 += (C00x) * (g73) * (2*beta*g191) * weight0;
            gout285 += (g35) * (C00y) * (2*beta*g154) * weight0;
            gout286 += (C00x) * (g103) * (2*beta*g154) * weight0;
            gout287 += (C00x) * (C00y) * (2*beta*g197) * weight0;
            gout288 += (g47) * (2*beta*g150) * weight0;
            gout289 += (g4) * (g101) * (2*beta*g150) * weight0;
            gout290 += (g4) * (2*beta*g193) * weight0;
            gout291 += (g35) * (D00y) * (2*beta*g150) * weight0;
            gout292 += (C00x) * (g109) * (2*beta*g150) * weight0;
            gout293 += (C00x) * (D00y) * (2*beta*g193) * weight0;
            gout294 += (g35) * (2*beta*g159) * weight0;
            gout295 += (C00x) * (g101) * (2*beta*g159) * weight0;
            gout296 += (C00x) * (2*beta*g200) * weight0;
            gout297 += (g41) * (g69) * (2*beta*g148) * weight0;
            gout298 += (D00x) * (g105) * (2*beta*g148) * weight0;
            gout299 += (D00x) * (g69) * (2*beta*g191) * weight0;
            gout300 += (g33) * (g76) * (2*beta*g148) * weight0;
            gout301 += (g118) * (2*beta*g148) * weight0;
            gout302 += (g76) * (2*beta*g191) * weight0;
            gout303 += (g33) * (g69) * (2*beta*g154) * weight0;
            gout304 += (g105) * (2*beta*g154) * weight0;
            gout305 += (g69) * (2*beta*g197) * weight0;
            gout306 += (g41) * (C00y) * (2*beta*g150) * weight0;
            gout307 += (D00x) * (g103) * (2*beta*g150) * weight0;
            gout308 += (D00x) * (C00y) * (2*beta*g193) * weight0;
            gout309 += (g33) * (g73) * (2*beta*g150) * weight0;
            gout310 += (g115) * (2*beta*g150) * weight0;
            gout311 += (g73) * (2*beta*g193) * weight0;
            gout312 += (g33) * (C00y) * (2*beta*g159) * weight0;
            gout313 += (g103) * (2*beta*g159) * weight0;
            gout314 += (C00y) * (2*beta*g200) * weight0;
            gout315 += (g41) * (2*beta*g152) * weight0;
            gout316 += (D00x) * (g101) * (2*beta*g152) * weight0;
            gout317 += (D00x) * (2*beta*g195) * weight0;
            gout318 += (g33) * (D00y) * (2*beta*g152) * weight0;
            gout319 += (g109) * (2*beta*g152) * weight0;
            gout320 += (D00y) * (2*beta*g195) * weight0;
            gout321 += (g33) * (2*beta*g167) * weight0;
            gout322 += (g101) * (2*beta*g167) * weight0;
            gout323 += (2*beta*g202) * weight0;
        }
    } }

    int *ao_loc = c_bpcache.ao_loc;
    int i0 = ao_loc[ish];
    int j0 = ao_loc[jsh];
    int k0 = ao_loc[ksh];
    int l0 = ao_loc[lsh];
    int n_dm = jk.n_dm;
    int nao = jk.nao;
    size_t nao2 = nao * nao;
    double* __restrict__ dm = jk.dm;
    double *vj = jk.vj;
    double *vk = jk.vk;
    double d_0, d_1, d_2, d_3, d_4, d_5, d_6, d_7, d_8, d_9, d_10, d_11, d_12, d_13, d_14, d_15, d_16, d_17;

    for (int i_dm = 0; i_dm < n_dm; ++i_dm) {
        if (vj != NULL) {
            d_0 = dm[(k0+0)+nao*(l0+0)];
            d_1 = dm[(k0+0)+nao*(l0+1)];
            d_2 = dm[(k0+0)+nao*(l0+2)];
            d_3 = dm[(k0+1)+nao*(l0+0)];
            d_4 = dm[(k0+1)+nao*(l0+1)];
            d_5 = dm[(k0+1)+nao*(l0+2)];
            d_6 = dm[(k0+2)+nao*(l0+0)];
            d_7 = dm[(k0+2)+nao*(l0+1)];
            d_8 = dm[(k0+2)+nao*(l0+2)];
            atomicAdd(vj+(i0+0)+nao*(j0+0), gout0*d_0+gout1*d_1+gout2*d_2+gout3*d_3+gout4*d_4+gout5*d_5+gout6*d_6+gout7*d_7+gout8*d_8);
            atomicAdd(vj+(i0+1)+nao*(j0+0), gout9*d_0+gout10*d_1+gout11*d_2+gout12*d_3+gout13*d_4+gout14*d_5+gout15*d_6+gout16*d_7+gout17*d_8);
            atomicAdd(vj+(i0+2)+nao*(j0+0), gout18*d_0+gout19*d_1+gout20*d_2+gout21*d_3+gout22*d_4+gout23*d_5+gout24*d_6+gout25*d_7+gout26*d_8);
            atomicAdd(vj+(i0+3)+nao*(j0+0), gout27*d_0+gout28*d_1+gout29*d_2+gout30*d_3+gout31*d_4+gout32*d_5+gout33*d_6+gout34*d_7+gout35*d_8);
            atomicAdd(vj+(i0+4)+nao*(j0+0), gout36*d_0+gout37*d_1+gout38*d_2+gout39*d_3+gout40*d_4+gout41*d_5+gout42*d_6+gout43*d_7+gout44*d_8);
            atomicAdd(vj+(i0+5)+nao*(j0+0), gout45*d_0+gout46*d_1+gout47*d_2+gout48*d_3+gout49*d_4+gout50*d_5+gout51*d_6+gout52*d_7+gout53*d_8);
            atomicAdd(vj+(i0+0)+nao*(j0+0)+nao2, gout54*d_0+gout55*d_1+gout56*d_2+gout57*d_3+gout58*d_4+gout59*d_5+gout60*d_6+gout61*d_7+gout62*d_8);
            atomicAdd(vj+(i0+1)+nao*(j0+0)+nao2, gout63*d_0+gout64*d_1+gout65*d_2+gout66*d_3+gout67*d_4+gout68*d_5+gout69*d_6+gout70*d_7+gout71*d_8);
            atomicAdd(vj+(i0+2)+nao*(j0+0)+nao2, gout72*d_0+gout73*d_1+gout74*d_2+gout75*d_3+gout76*d_4+gout77*d_5+gout78*d_6+gout79*d_7+gout80*d_8);
            atomicAdd(vj+(i0+3)+nao*(j0+0)+nao2, gout81*d_0+gout82*d_1+gout83*d_2+gout84*d_3+gout85*d_4+gout86*d_5+gout87*d_6+gout88*d_7+gout89*d_8);
            atomicAdd(vj+(i0+4)+nao*(j0+0)+nao2, gout90*d_0+gout91*d_1+gout92*d_2+gout93*d_3+gout94*d_4+gout95*d_5+gout96*d_6+gout97*d_7+gout98*d_8);
            atomicAdd(vj+(i0+5)+nao*(j0+0)+nao2, gout99*d_0+gout100*d_1+gout101*d_2+gout102*d_3+gout103*d_4+gout104*d_5+gout105*d_6+gout106*d_7+gout107*d_8);
            atomicAdd(vj+(i0+0)+nao*(j0+0)+2*nao2, gout108*d_0+gout109*d_1+gout110*d_2+gout111*d_3+gout112*d_4+gout113*d_5+gout114*d_6+gout115*d_7+gout116*d_8);
            atomicAdd(vj+(i0+1)+nao*(j0+0)+2*nao2, gout117*d_0+gout118*d_1+gout119*d_2+gout120*d_3+gout121*d_4+gout122*d_5+gout123*d_6+gout124*d_7+gout125*d_8);
            atomicAdd(vj+(i0+2)+nao*(j0+0)+2*nao2, gout126*d_0+gout127*d_1+gout128*d_2+gout129*d_3+gout130*d_4+gout131*d_5+gout132*d_6+gout133*d_7+gout134*d_8);
            atomicAdd(vj+(i0+3)+nao*(j0+0)+2*nao2, gout135*d_0+gout136*d_1+gout137*d_2+gout138*d_3+gout139*d_4+gout140*d_5+gout141*d_6+gout142*d_7+gout143*d_8);
            atomicAdd(vj+(i0+4)+nao*(j0+0)+2*nao2, gout144*d_0+gout145*d_1+gout146*d_2+gout147*d_3+gout148*d_4+gout149*d_5+gout150*d_6+gout151*d_7+gout152*d_8);
            atomicAdd(vj+(i0+5)+nao*(j0+0)+2*nao2, gout153*d_0+gout154*d_1+gout155*d_2+gout156*d_3+gout157*d_4+gout158*d_5+gout159*d_6+gout160*d_7+gout161*d_8);
            atomicAdd(vj+nao*(i0+0)+(j0+0), gout162*d_0+gout163*d_1+gout164*d_2+gout165*d_3+gout166*d_4+gout167*d_5+gout168*d_6+gout169*d_7+gout170*d_8);
            atomicAdd(vj+nao*(i0+1)+(j0+0), gout171*d_0+gout172*d_1+gout173*d_2+gout174*d_3+gout175*d_4+gout176*d_5+gout177*d_6+gout178*d_7+gout179*d_8);
            atomicAdd(vj+nao*(i0+2)+(j0+0), gout180*d_0+gout181*d_1+gout182*d_2+gout183*d_3+gout184*d_4+gout185*d_5+gout186*d_6+gout187*d_7+gout188*d_8);
            atomicAdd(vj+nao*(i0+3)+(j0+0), gout189*d_0+gout190*d_1+gout191*d_2+gout192*d_3+gout193*d_4+gout194*d_5+gout195*d_6+gout196*d_7+gout197*d_8);
            atomicAdd(vj+nao*(i0+4)+(j0+0), gout198*d_0+gout199*d_1+gout200*d_2+gout201*d_3+gout202*d_4+gout203*d_5+gout204*d_6+gout205*d_7+gout206*d_8);
            atomicAdd(vj+nao*(i0+5)+(j0+0), gout207*d_0+gout208*d_1+gout209*d_2+gout210*d_3+gout211*d_4+gout212*d_5+gout213*d_6+gout214*d_7+gout215*d_8);
            atomicAdd(vj+nao*(i0+0)+(j0+0)+nao2, gout216*d_0+gout217*d_1+gout218*d_2+gout219*d_3+gout220*d_4+gout221*d_5+gout222*d_6+gout223*d_7+gout224*d_8);
            atomicAdd(vj+nao*(i0+1)+(j0+0)+nao2, gout225*d_0+gout226*d_1+gout227*d_2+gout228*d_3+gout229*d_4+gout230*d_5+gout231*d_6+gout232*d_7+gout233*d_8);
            atomicAdd(vj+nao*(i0+2)+(j0+0)+nao2, gout234*d_0+gout235*d_1+gout236*d_2+gout237*d_3+gout238*d_4+gout239*d_5+gout240*d_6+gout241*d_7+gout242*d_8);
            atomicAdd(vj+nao*(i0+3)+(j0+0)+nao2, gout243*d_0+gout244*d_1+gout245*d_2+gout246*d_3+gout247*d_4+gout248*d_5+gout249*d_6+gout250*d_7+gout251*d_8);
            atomicAdd(vj+nao*(i0+4)+(j0+0)+nao2, gout252*d_0+gout253*d_1+gout254*d_2+gout255*d_3+gout256*d_4+gout257*d_5+gout258*d_6+gout259*d_7+gout260*d_8);
            atomicAdd(vj+nao*(i0+5)+(j0+0)+nao2, gout261*d_0+gout262*d_1+gout263*d_2+gout264*d_3+gout265*d_4+gout266*d_5+gout267*d_6+gout268*d_7+gout269*d_8);
            atomicAdd(vj+nao*(i0+0)+(j0+0)+2*nao2, gout270*d_0+gout271*d_1+gout272*d_2+gout273*d_3+gout274*d_4+gout275*d_5+gout276*d_6+gout277*d_7+gout278*d_8);
            atomicAdd(vj+nao*(i0+1)+(j0+0)+2*nao2, gout279*d_0+gout280*d_1+gout281*d_2+gout282*d_3+gout283*d_4+gout284*d_5+gout285*d_6+gout286*d_7+gout287*d_8);
            atomicAdd(vj+nao*(i0+2)+(j0+0)+2*nao2, gout288*d_0+gout289*d_1+gout290*d_2+gout291*d_3+gout292*d_4+gout293*d_5+gout294*d_6+gout295*d_7+gout296*d_8);
            atomicAdd(vj+nao*(i0+3)+(j0+0)+2*nao2, gout297*d_0+gout298*d_1+gout299*d_2+gout300*d_3+gout301*d_4+gout302*d_5+gout303*d_6+gout304*d_7+gout305*d_8);
            atomicAdd(vj+nao*(i0+4)+(j0+0)+2*nao2, gout306*d_0+gout307*d_1+gout308*d_2+gout309*d_3+gout310*d_4+gout311*d_5+gout312*d_6+gout313*d_7+gout314*d_8);
            atomicAdd(vj+nao*(i0+5)+(j0+0)+2*nao2, gout315*d_0+gout316*d_1+gout317*d_2+gout318*d_3+gout319*d_4+gout320*d_5+gout321*d_6+gout322*d_7+gout323*d_8);
            vj += 3*nao2;
        }
        if (vk != NULL) {
            // ijkl, jk -> il
            d_0 = dm[(j0+0)+nao*(k0+0)];
            d_1 = dm[(j0+0)+nao*(k0+1)];
            d_2 = dm[(j0+0)+nao*(k0+2)];
            atomicAdd(vk+(i0+0)+nao*(l0+0), gout0*d_0+gout3*d_1+gout6*d_2);
            atomicAdd(vk+(i0+0)+nao*(l0+1), gout1*d_0+gout4*d_1+gout7*d_2);
            atomicAdd(vk+(i0+0)+nao*(l0+2), gout2*d_0+gout5*d_1+gout8*d_2);
            atomicAdd(vk+(i0+1)+nao*(l0+0), gout9*d_0+gout12*d_1+gout15*d_2);
            atomicAdd(vk+(i0+1)+nao*(l0+1), gout10*d_0+gout13*d_1+gout16*d_2);
            atomicAdd(vk+(i0+1)+nao*(l0+2), gout11*d_0+gout14*d_1+gout17*d_2);
            atomicAdd(vk+(i0+2)+nao*(l0+0), gout18*d_0+gout21*d_1+gout24*d_2);
            atomicAdd(vk+(i0+2)+nao*(l0+1), gout19*d_0+gout22*d_1+gout25*d_2);
            atomicAdd(vk+(i0+2)+nao*(l0+2), gout20*d_0+gout23*d_1+gout26*d_2);
            atomicAdd(vk+(i0+3)+nao*(l0+0), gout27*d_0+gout30*d_1+gout33*d_2);
            atomicAdd(vk+(i0+3)+nao*(l0+1), gout28*d_0+gout31*d_1+gout34*d_2);
            atomicAdd(vk+(i0+3)+nao*(l0+2), gout29*d_0+gout32*d_1+gout35*d_2);
            atomicAdd(vk+(i0+4)+nao*(l0+0), gout36*d_0+gout39*d_1+gout42*d_2);
            atomicAdd(vk+(i0+4)+nao*(l0+1), gout37*d_0+gout40*d_1+gout43*d_2);
            atomicAdd(vk+(i0+4)+nao*(l0+2), gout38*d_0+gout41*d_1+gout44*d_2);
            atomicAdd(vk+(i0+5)+nao*(l0+0), gout45*d_0+gout48*d_1+gout51*d_2);
            atomicAdd(vk+(i0+5)+nao*(l0+1), gout46*d_0+gout49*d_1+gout52*d_2);
            atomicAdd(vk+(i0+5)+nao*(l0+2), gout47*d_0+gout50*d_1+gout53*d_2);
            atomicAdd(vk+(i0+0)+nao*(l0+0)+nao2, gout54*d_0+gout57*d_1+gout60*d_2);
            atomicAdd(vk+(i0+0)+nao*(l0+1)+nao2, gout55*d_0+gout58*d_1+gout61*d_2);
            atomicAdd(vk+(i0+0)+nao*(l0+2)+nao2, gout56*d_0+gout59*d_1+gout62*d_2);
            atomicAdd(vk+(i0+1)+nao*(l0+0)+nao2, gout63*d_0+gout66*d_1+gout69*d_2);
            atomicAdd(vk+(i0+1)+nao*(l0+1)+nao2, gout64*d_0+gout67*d_1+gout70*d_2);
            atomicAdd(vk+(i0+1)+nao*(l0+2)+nao2, gout65*d_0+gout68*d_1+gout71*d_2);
            atomicAdd(vk+(i0+2)+nao*(l0+0)+nao2, gout72*d_0+gout75*d_1+gout78*d_2);
            atomicAdd(vk+(i0+2)+nao*(l0+1)+nao2, gout73*d_0+gout76*d_1+gout79*d_2);
            atomicAdd(vk+(i0+2)+nao*(l0+2)+nao2, gout74*d_0+gout77*d_1+gout80*d_2);
            atomicAdd(vk+(i0+3)+nao*(l0+0)+nao2, gout81*d_0+gout84*d_1+gout87*d_2);
            atomicAdd(vk+(i0+3)+nao*(l0+1)+nao2, gout82*d_0+gout85*d_1+gout88*d_2);
            atomicAdd(vk+(i0+3)+nao*(l0+2)+nao2, gout83*d_0+gout86*d_1+gout89*d_2);
            atomicAdd(vk+(i0+4)+nao*(l0+0)+nao2, gout90*d_0+gout93*d_1+gout96*d_2);
            atomicAdd(vk+(i0+4)+nao*(l0+1)+nao2, gout91*d_0+gout94*d_1+gout97*d_2);
            atomicAdd(vk+(i0+4)+nao*(l0+2)+nao2, gout92*d_0+gout95*d_1+gout98*d_2);
            atomicAdd(vk+(i0+5)+nao*(l0+0)+nao2, gout99*d_0+gout102*d_1+gout105*d_2);
            atomicAdd(vk+(i0+5)+nao*(l0+1)+nao2, gout100*d_0+gout103*d_1+gout106*d_2);
            atomicAdd(vk+(i0+5)+nao*(l0+2)+nao2, gout101*d_0+gout104*d_1+gout107*d_2);
            atomicAdd(vk+(i0+0)+nao*(l0+0)+2*nao2, gout108*d_0+gout111*d_1+gout114*d_2);
            atomicAdd(vk+(i0+0)+nao*(l0+1)+2*nao2, gout109*d_0+gout112*d_1+gout115*d_2);
            atomicAdd(vk+(i0+0)+nao*(l0+2)+2*nao2, gout110*d_0+gout113*d_1+gout116*d_2);
            atomicAdd(vk+(i0+1)+nao*(l0+0)+2*nao2, gout117*d_0+gout120*d_1+gout123*d_2);
            atomicAdd(vk+(i0+1)+nao*(l0+1)+2*nao2, gout118*d_0+gout121*d_1+gout124*d_2);
            atomicAdd(vk+(i0+1)+nao*(l0+2)+2*nao2, gout119*d_0+gout122*d_1+gout125*d_2);
            atomicAdd(vk+(i0+2)+nao*(l0+0)+2*nao2, gout126*d_0+gout129*d_1+gout132*d_2);
            atomicAdd(vk+(i0+2)+nao*(l0+1)+2*nao2, gout127*d_0+gout130*d_1+gout133*d_2);
            atomicAdd(vk+(i0+2)+nao*(l0+2)+2*nao2, gout128*d_0+gout131*d_1+gout134*d_2);
            atomicAdd(vk+(i0+3)+nao*(l0+0)+2*nao2, gout135*d_0+gout138*d_1+gout141*d_2);
            atomicAdd(vk+(i0+3)+nao*(l0+1)+2*nao2, gout136*d_0+gout139*d_1+gout142*d_2);
            atomicAdd(vk+(i0+3)+nao*(l0+2)+2*nao2, gout137*d_0+gout140*d_1+gout143*d_2);
            atomicAdd(vk+(i0+4)+nao*(l0+0)+2*nao2, gout144*d_0+gout147*d_1+gout150*d_2);
            atomicAdd(vk+(i0+4)+nao*(l0+1)+2*nao2, gout145*d_0+gout148*d_1+gout151*d_2);
            atomicAdd(vk+(i0+4)+nao*(l0+2)+2*nao2, gout146*d_0+gout149*d_1+gout152*d_2);
            atomicAdd(vk+(i0+5)+nao*(l0+0)+2*nao2, gout153*d_0+gout156*d_1+gout159*d_2);
            atomicAdd(vk+(i0+5)+nao*(l0+1)+2*nao2, gout154*d_0+gout157*d_1+gout160*d_2);
            atomicAdd(vk+(i0+5)+nao*(l0+2)+2*nao2, gout155*d_0+gout158*d_1+gout161*d_2);
            // ijkl, jl -> ik
            d_0 = dm[(j0+0)+nao*(l0+0)];
            d_1 = dm[(j0+0)+nao*(l0+1)];
            d_2 = dm[(j0+0)+nao*(l0+2)];
            atomicAdd(vk+(i0+0)+nao*(k0+0), gout0*d_0+gout1*d_1+gout2*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+1), gout3*d_0+gout4*d_1+gout5*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+2), gout6*d_0+gout7*d_1+gout8*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+0), gout9*d_0+gout10*d_1+gout11*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+1), gout12*d_0+gout13*d_1+gout14*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+2), gout15*d_0+gout16*d_1+gout17*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+0), gout18*d_0+gout19*d_1+gout20*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+1), gout21*d_0+gout22*d_1+gout23*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+2), gout24*d_0+gout25*d_1+gout26*d_2);
            atomicAdd(vk+(i0+3)+nao*(k0+0), gout27*d_0+gout28*d_1+gout29*d_2);
            atomicAdd(vk+(i0+3)+nao*(k0+1), gout30*d_0+gout31*d_1+gout32*d_2);
            atomicAdd(vk+(i0+3)+nao*(k0+2), gout33*d_0+gout34*d_1+gout35*d_2);
            atomicAdd(vk+(i0+4)+nao*(k0+0), gout36*d_0+gout37*d_1+gout38*d_2);
            atomicAdd(vk+(i0+4)+nao*(k0+1), gout39*d_0+gout40*d_1+gout41*d_2);
            atomicAdd(vk+(i0+4)+nao*(k0+2), gout42*d_0+gout43*d_1+gout44*d_2);
            atomicAdd(vk+(i0+5)+nao*(k0+0), gout45*d_0+gout46*d_1+gout47*d_2);
            atomicAdd(vk+(i0+5)+nao*(k0+1), gout48*d_0+gout49*d_1+gout50*d_2);
            atomicAdd(vk+(i0+5)+nao*(k0+2), gout51*d_0+gout52*d_1+gout53*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+0)+nao2, gout54*d_0+gout55*d_1+gout56*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+1)+nao2, gout57*d_0+gout58*d_1+gout59*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+2)+nao2, gout60*d_0+gout61*d_1+gout62*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+0)+nao2, gout63*d_0+gout64*d_1+gout65*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+1)+nao2, gout66*d_0+gout67*d_1+gout68*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+2)+nao2, gout69*d_0+gout70*d_1+gout71*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+0)+nao2, gout72*d_0+gout73*d_1+gout74*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+1)+nao2, gout75*d_0+gout76*d_1+gout77*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+2)+nao2, gout78*d_0+gout79*d_1+gout80*d_2);
            atomicAdd(vk+(i0+3)+nao*(k0+0)+nao2, gout81*d_0+gout82*d_1+gout83*d_2);
            atomicAdd(vk+(i0+3)+nao*(k0+1)+nao2, gout84*d_0+gout85*d_1+gout86*d_2);
            atomicAdd(vk+(i0+3)+nao*(k0+2)+nao2, gout87*d_0+gout88*d_1+gout89*d_2);
            atomicAdd(vk+(i0+4)+nao*(k0+0)+nao2, gout90*d_0+gout91*d_1+gout92*d_2);
            atomicAdd(vk+(i0+4)+nao*(k0+1)+nao2, gout93*d_0+gout94*d_1+gout95*d_2);
            atomicAdd(vk+(i0+4)+nao*(k0+2)+nao2, gout96*d_0+gout97*d_1+gout98*d_2);
            atomicAdd(vk+(i0+5)+nao*(k0+0)+nao2, gout99*d_0+gout100*d_1+gout101*d_2);
            atomicAdd(vk+(i0+5)+nao*(k0+1)+nao2, gout102*d_0+gout103*d_1+gout104*d_2);
            atomicAdd(vk+(i0+5)+nao*(k0+2)+nao2, gout105*d_0+gout106*d_1+gout107*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+0)+2*nao2, gout108*d_0+gout109*d_1+gout110*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+1)+2*nao2, gout111*d_0+gout112*d_1+gout113*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+2)+2*nao2, gout114*d_0+gout115*d_1+gout116*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+0)+2*nao2, gout117*d_0+gout118*d_1+gout119*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+1)+2*nao2, gout120*d_0+gout121*d_1+gout122*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+2)+2*nao2, gout123*d_0+gout124*d_1+gout125*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+0)+2*nao2, gout126*d_0+gout127*d_1+gout128*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+1)+2*nao2, gout129*d_0+gout130*d_1+gout131*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+2)+2*nao2, gout132*d_0+gout133*d_1+gout134*d_2);
            atomicAdd(vk+(i0+3)+nao*(k0+0)+2*nao2, gout135*d_0+gout136*d_1+gout137*d_2);
            atomicAdd(vk+(i0+3)+nao*(k0+1)+2*nao2, gout138*d_0+gout139*d_1+gout140*d_2);
            atomicAdd(vk+(i0+3)+nao*(k0+2)+2*nao2, gout141*d_0+gout142*d_1+gout143*d_2);
            atomicAdd(vk+(i0+4)+nao*(k0+0)+2*nao2, gout144*d_0+gout145*d_1+gout146*d_2);
            atomicAdd(vk+(i0+4)+nao*(k0+1)+2*nao2, gout147*d_0+gout148*d_1+gout149*d_2);
            atomicAdd(vk+(i0+4)+nao*(k0+2)+2*nao2, gout150*d_0+gout151*d_1+gout152*d_2);
            atomicAdd(vk+(i0+5)+nao*(k0+0)+2*nao2, gout153*d_0+gout154*d_1+gout155*d_2);
            atomicAdd(vk+(i0+5)+nao*(k0+1)+2*nao2, gout156*d_0+gout157*d_1+gout158*d_2);
            atomicAdd(vk+(i0+5)+nao*(k0+2)+2*nao2, gout159*d_0+gout160*d_1+gout161*d_2);
            // ijkl, ik -> jl
            d_0 = dm[(i0+0)+nao*(k0+0)];
            d_1 = dm[(i0+0)+nao*(k0+1)];
            d_2 = dm[(i0+0)+nao*(k0+2)];
            d_3 = dm[(i0+1)+nao*(k0+0)];
            d_4 = dm[(i0+1)+nao*(k0+1)];
            d_5 = dm[(i0+1)+nao*(k0+2)];
            d_6 = dm[(i0+2)+nao*(k0+0)];
            d_7 = dm[(i0+2)+nao*(k0+1)];
            d_8 = dm[(i0+2)+nao*(k0+2)];
            d_9 = dm[(i0+3)+nao*(k0+0)];
            d_10 = dm[(i0+3)+nao*(k0+1)];
            d_11 = dm[(i0+3)+nao*(k0+2)];
            d_12 = dm[(i0+4)+nao*(k0+0)];
            d_13 = dm[(i0+4)+nao*(k0+1)];
            d_14 = dm[(i0+4)+nao*(k0+2)];
            d_15 = dm[(i0+5)+nao*(k0+0)];
            d_16 = dm[(i0+5)+nao*(k0+1)];
            d_17 = dm[(i0+5)+nao*(k0+2)];
            atomicAdd(vk+(j0+0)+nao*(l0+0), gout162*d_0+gout165*d_1+gout168*d_2+gout171*d_3+gout174*d_4+gout177*d_5+gout180*d_6+gout183*d_7+gout186*d_8+gout189*d_9+gout192*d_10+gout195*d_11+gout198*d_12+gout201*d_13+gout204*d_14+gout207*d_15+gout210*d_16+gout213*d_17);
            atomicAdd(vk+(j0+0)+nao*(l0+1), gout163*d_0+gout166*d_1+gout169*d_2+gout172*d_3+gout175*d_4+gout178*d_5+gout181*d_6+gout184*d_7+gout187*d_8+gout190*d_9+gout193*d_10+gout196*d_11+gout199*d_12+gout202*d_13+gout205*d_14+gout208*d_15+gout211*d_16+gout214*d_17);
            atomicAdd(vk+(j0+0)+nao*(l0+2), gout164*d_0+gout167*d_1+gout170*d_2+gout173*d_3+gout176*d_4+gout179*d_5+gout182*d_6+gout185*d_7+gout188*d_8+gout191*d_9+gout194*d_10+gout197*d_11+gout200*d_12+gout203*d_13+gout206*d_14+gout209*d_15+gout212*d_16+gout215*d_17);
            atomicAdd(vk+(j0+0)+nao*(l0+0)+nao2, gout216*d_0+gout219*d_1+gout222*d_2+gout225*d_3+gout228*d_4+gout231*d_5+gout234*d_6+gout237*d_7+gout240*d_8+gout243*d_9+gout246*d_10+gout249*d_11+gout252*d_12+gout255*d_13+gout258*d_14+gout261*d_15+gout264*d_16+gout267*d_17);
            atomicAdd(vk+(j0+0)+nao*(l0+1)+nao2, gout217*d_0+gout220*d_1+gout223*d_2+gout226*d_3+gout229*d_4+gout232*d_5+gout235*d_6+gout238*d_7+gout241*d_8+gout244*d_9+gout247*d_10+gout250*d_11+gout253*d_12+gout256*d_13+gout259*d_14+gout262*d_15+gout265*d_16+gout268*d_17);
            atomicAdd(vk+(j0+0)+nao*(l0+2)+nao2, gout218*d_0+gout221*d_1+gout224*d_2+gout227*d_3+gout230*d_4+gout233*d_5+gout236*d_6+gout239*d_7+gout242*d_8+gout245*d_9+gout248*d_10+gout251*d_11+gout254*d_12+gout257*d_13+gout260*d_14+gout263*d_15+gout266*d_16+gout269*d_17);
            atomicAdd(vk+(j0+0)+nao*(l0+0)+2*nao2, gout270*d_0+gout273*d_1+gout276*d_2+gout279*d_3+gout282*d_4+gout285*d_5+gout288*d_6+gout291*d_7+gout294*d_8+gout297*d_9+gout300*d_10+gout303*d_11+gout306*d_12+gout309*d_13+gout312*d_14+gout315*d_15+gout318*d_16+gout321*d_17);
            atomicAdd(vk+(j0+0)+nao*(l0+1)+2*nao2, gout271*d_0+gout274*d_1+gout277*d_2+gout280*d_3+gout283*d_4+gout286*d_5+gout289*d_6+gout292*d_7+gout295*d_8+gout298*d_9+gout301*d_10+gout304*d_11+gout307*d_12+gout310*d_13+gout313*d_14+gout316*d_15+gout319*d_16+gout322*d_17);
            atomicAdd(vk+(j0+0)+nao*(l0+2)+2*nao2, gout272*d_0+gout275*d_1+gout278*d_2+gout281*d_3+gout284*d_4+gout287*d_5+gout290*d_6+gout293*d_7+gout296*d_8+gout299*d_9+gout302*d_10+gout305*d_11+gout308*d_12+gout311*d_13+gout314*d_14+gout317*d_15+gout320*d_16+gout323*d_17);
            // ijkl, il -> jk
            d_0 = dm[(i0+0)+nao*(l0+0)];
            d_1 = dm[(i0+0)+nao*(l0+1)];
            d_2 = dm[(i0+0)+nao*(l0+2)];
            d_3 = dm[(i0+1)+nao*(l0+0)];
            d_4 = dm[(i0+1)+nao*(l0+1)];
            d_5 = dm[(i0+1)+nao*(l0+2)];
            d_6 = dm[(i0+2)+nao*(l0+0)];
            d_7 = dm[(i0+2)+nao*(l0+1)];
            d_8 = dm[(i0+2)+nao*(l0+2)];
            d_9 = dm[(i0+3)+nao*(l0+0)];
            d_10 = dm[(i0+3)+nao*(l0+1)];
            d_11 = dm[(i0+3)+nao*(l0+2)];
            d_12 = dm[(i0+4)+nao*(l0+0)];
            d_13 = dm[(i0+4)+nao*(l0+1)];
            d_14 = dm[(i0+4)+nao*(l0+2)];
            d_15 = dm[(i0+5)+nao*(l0+0)];
            d_16 = dm[(i0+5)+nao*(l0+1)];
            d_17 = dm[(i0+5)+nao*(l0+2)];
            atomicAdd(vk+(j0+0)+nao*(k0+0), gout162*d_0+gout163*d_1+gout164*d_2+gout171*d_3+gout172*d_4+gout173*d_5+gout180*d_6+gout181*d_7+gout182*d_8+gout189*d_9+gout190*d_10+gout191*d_11+gout198*d_12+gout199*d_13+gout200*d_14+gout207*d_15+gout208*d_16+gout209*d_17);
            atomicAdd(vk+(j0+0)+nao*(k0+1), gout165*d_0+gout166*d_1+gout167*d_2+gout174*d_3+gout175*d_4+gout176*d_5+gout183*d_6+gout184*d_7+gout185*d_8+gout192*d_9+gout193*d_10+gout194*d_11+gout201*d_12+gout202*d_13+gout203*d_14+gout210*d_15+gout211*d_16+gout212*d_17);
            atomicAdd(vk+(j0+0)+nao*(k0+2), gout168*d_0+gout169*d_1+gout170*d_2+gout177*d_3+gout178*d_4+gout179*d_5+gout186*d_6+gout187*d_7+gout188*d_8+gout195*d_9+gout196*d_10+gout197*d_11+gout204*d_12+gout205*d_13+gout206*d_14+gout213*d_15+gout214*d_16+gout215*d_17);
            atomicAdd(vk+(j0+0)+nao*(k0+0)+nao2, gout216*d_0+gout217*d_1+gout218*d_2+gout225*d_3+gout226*d_4+gout227*d_5+gout234*d_6+gout235*d_7+gout236*d_8+gout243*d_9+gout244*d_10+gout245*d_11+gout252*d_12+gout253*d_13+gout254*d_14+gout261*d_15+gout262*d_16+gout263*d_17);
            atomicAdd(vk+(j0+0)+nao*(k0+1)+nao2, gout219*d_0+gout220*d_1+gout221*d_2+gout228*d_3+gout229*d_4+gout230*d_5+gout237*d_6+gout238*d_7+gout239*d_8+gout246*d_9+gout247*d_10+gout248*d_11+gout255*d_12+gout256*d_13+gout257*d_14+gout264*d_15+gout265*d_16+gout266*d_17);
            atomicAdd(vk+(j0+0)+nao*(k0+2)+nao2, gout222*d_0+gout223*d_1+gout224*d_2+gout231*d_3+gout232*d_4+gout233*d_5+gout240*d_6+gout241*d_7+gout242*d_8+gout249*d_9+gout250*d_10+gout251*d_11+gout258*d_12+gout259*d_13+gout260*d_14+gout267*d_15+gout268*d_16+gout269*d_17);
            atomicAdd(vk+(j0+0)+nao*(k0+0)+2*nao2, gout270*d_0+gout271*d_1+gout272*d_2+gout279*d_3+gout280*d_4+gout281*d_5+gout288*d_6+gout289*d_7+gout290*d_8+gout297*d_9+gout298*d_10+gout299*d_11+gout306*d_12+gout307*d_13+gout308*d_14+gout315*d_15+gout316*d_16+gout317*d_17);
            atomicAdd(vk+(j0+0)+nao*(k0+1)+2*nao2, gout273*d_0+gout274*d_1+gout275*d_2+gout282*d_3+gout283*d_4+gout284*d_5+gout291*d_6+gout292*d_7+gout293*d_8+gout300*d_9+gout301*d_10+gout302*d_11+gout309*d_12+gout310*d_13+gout311*d_14+gout318*d_15+gout319*d_16+gout320*d_17);
            atomicAdd(vk+(j0+0)+nao*(k0+2)+2*nao2, gout276*d_0+gout277*d_1+gout278*d_2+gout285*d_3+gout286*d_4+gout287*d_5+gout294*d_6+gout295*d_7+gout296*d_8+gout303*d_9+gout304*d_10+gout305*d_11+gout312*d_12+gout313*d_13+gout314*d_14+gout321*d_15+gout322*d_16+gout323*d_17);
            vk += 3*nao2;
        }
        dm += nao2;
    }
}

__global__
static void GINTint2e_ip1_jk_kernel_2020(GINTEnvVars envs, JKMatrix jk,
                                    BasisProdOffsets offsets)
{
    int ntasks_ij = offsets.ntasks_ij;
    int ntasks_kl = offsets.ntasks_kl;
    int task_ij = blockIdx.x * blockDim.x + threadIdx.x;
    int task_kl = blockIdx.y * blockDim.y + threadIdx.y;
    if (task_ij >= ntasks_ij || task_kl >= ntasks_kl) {
        return;
    }
    int bas_ij = offsets.bas_ij + task_ij;
    int bas_kl = offsets.bas_kl + task_kl;
    double norm = envs.fac;
    double omega = envs.omega;
    int *bas_pair2bra = c_bpcache.bas_pair2bra;
    int *bas_pair2ket = c_bpcache.bas_pair2ket;
    int ish = bas_pair2bra[bas_ij];
    int jsh = bas_pair2ket[bas_ij];
    int ksh = bas_pair2bra[bas_kl];
    int lsh = bas_pair2ket[bas_kl];
    int nprim_ij = envs.nprim_ij;
    int nprim_kl = envs.nprim_kl;
    int prim_ij = offsets.primitive_ij + task_ij * nprim_ij;
    int prim_kl = offsets.primitive_kl + task_kl * nprim_kl;

    double* __restrict__ a12 = c_bpcache.a12;
    double* __restrict__ e12 = c_bpcache.e12;
    double* __restrict__ x12 = c_bpcache.x12;
    double* __restrict__ y12 = c_bpcache.y12;
    double* __restrict__ z12 = c_bpcache.z12;
    double * __restrict__ i_exponent = c_bpcache.a1;
    double * __restrict__ j_exponent = c_bpcache.a2;

    int ij, kl;
    int prim_ij0, prim_ij1, prim_kl0, prim_kl1;
    int nbas = c_bpcache.nbas;
    double* __restrict__ bas_x = c_bpcache.bas_coords;
    double* __restrict__ bas_y = bas_x + nbas;
    double* __restrict__ bas_z = bas_y + nbas;

    double gout0 = 0;
    double gout1 = 0;
    double gout2 = 0;
    double gout3 = 0;
    double gout4 = 0;
    double gout5 = 0;
    double gout6 = 0;
    double gout7 = 0;
    double gout8 = 0;
    double gout9 = 0;
    double gout10 = 0;
    double gout11 = 0;
    double gout12 = 0;
    double gout13 = 0;
    double gout14 = 0;
    double gout15 = 0;
    double gout16 = 0;
    double gout17 = 0;
    double gout18 = 0;
    double gout19 = 0;
    double gout20 = 0;
    double gout21 = 0;
    double gout22 = 0;
    double gout23 = 0;
    double gout24 = 0;
    double gout25 = 0;
    double gout26 = 0;
    double gout27 = 0;
    double gout28 = 0;
    double gout29 = 0;
    double gout30 = 0;
    double gout31 = 0;
    double gout32 = 0;
    double gout33 = 0;
    double gout34 = 0;
    double gout35 = 0;
    double gout36 = 0;
    double gout37 = 0;
    double gout38 = 0;
    double gout39 = 0;
    double gout40 = 0;
    double gout41 = 0;
    double gout42 = 0;
    double gout43 = 0;
    double gout44 = 0;
    double gout45 = 0;
    double gout46 = 0;
    double gout47 = 0;
    double gout48 = 0;
    double gout49 = 0;
    double gout50 = 0;
    double gout51 = 0;
    double gout52 = 0;
    double gout53 = 0;
    double gout54 = 0;
    double gout55 = 0;
    double gout56 = 0;
    double gout57 = 0;
    double gout58 = 0;
    double gout59 = 0;
    double gout60 = 0;
    double gout61 = 0;
    double gout62 = 0;
    double gout63 = 0;
    double gout64 = 0;
    double gout65 = 0;
    double gout66 = 0;
    double gout67 = 0;
    double gout68 = 0;
    double gout69 = 0;
    double gout70 = 0;
    double gout71 = 0;
    double gout72 = 0;
    double gout73 = 0;
    double gout74 = 0;
    double gout75 = 0;
    double gout76 = 0;
    double gout77 = 0;
    double gout78 = 0;
    double gout79 = 0;
    double gout80 = 0;
    double gout81 = 0;
    double gout82 = 0;
    double gout83 = 0;
    double gout84 = 0;
    double gout85 = 0;
    double gout86 = 0;
    double gout87 = 0;
    double gout88 = 0;
    double gout89 = 0;
    double gout90 = 0;
    double gout91 = 0;
    double gout92 = 0;
    double gout93 = 0;
    double gout94 = 0;
    double gout95 = 0;
    double gout96 = 0;
    double gout97 = 0;
    double gout98 = 0;
    double gout99 = 0;
    double gout100 = 0;
    double gout101 = 0;
    double gout102 = 0;
    double gout103 = 0;
    double gout104 = 0;
    double gout105 = 0;
    double gout106 = 0;
    double gout107 = 0;
    double gout108 = 0;
    double gout109 = 0;
    double gout110 = 0;
    double gout111 = 0;
    double gout112 = 0;
    double gout113 = 0;
    double gout114 = 0;
    double gout115 = 0;
    double gout116 = 0;
    double gout117 = 0;
    double gout118 = 0;
    double gout119 = 0;
    double gout120 = 0;
    double gout121 = 0;
    double gout122 = 0;
    double gout123 = 0;
    double gout124 = 0;
    double gout125 = 0;
    double gout126 = 0;
    double gout127 = 0;
    double gout128 = 0;
    double gout129 = 0;
    double gout130 = 0;
    double gout131 = 0;
    double gout132 = 0;
    double gout133 = 0;
    double gout134 = 0;
    double gout135 = 0;
    double gout136 = 0;
    double gout137 = 0;
    double gout138 = 0;
    double gout139 = 0;
    double gout140 = 0;
    double gout141 = 0;
    double gout142 = 0;
    double gout143 = 0;
    double gout144 = 0;
    double gout145 = 0;
    double gout146 = 0;
    double gout147 = 0;
    double gout148 = 0;
    double gout149 = 0;
    double gout150 = 0;
    double gout151 = 0;
    double gout152 = 0;
    double gout153 = 0;
    double gout154 = 0;
    double gout155 = 0;
    double gout156 = 0;
    double gout157 = 0;
    double gout158 = 0;
    double gout159 = 0;
    double gout160 = 0;
    double gout161 = 0;
    double gout162 = 0;
    double gout163 = 0;
    double gout164 = 0;
    double gout165 = 0;
    double gout166 = 0;
    double gout167 = 0;
    double gout168 = 0;
    double gout169 = 0;
    double gout170 = 0;
    double gout171 = 0;
    double gout172 = 0;
    double gout173 = 0;
    double gout174 = 0;
    double gout175 = 0;
    double gout176 = 0;
    double gout177 = 0;
    double gout178 = 0;
    double gout179 = 0;
    double gout180 = 0;
    double gout181 = 0;
    double gout182 = 0;
    double gout183 = 0;
    double gout184 = 0;
    double gout185 = 0;
    double gout186 = 0;
    double gout187 = 0;
    double gout188 = 0;
    double gout189 = 0;
    double gout190 = 0;
    double gout191 = 0;
    double gout192 = 0;
    double gout193 = 0;
    double gout194 = 0;
    double gout195 = 0;
    double gout196 = 0;
    double gout197 = 0;
    double gout198 = 0;
    double gout199 = 0;
    double gout200 = 0;
    double gout201 = 0;
    double gout202 = 0;
    double gout203 = 0;
    double gout204 = 0;
    double gout205 = 0;
    double gout206 = 0;
    double gout207 = 0;
    double gout208 = 0;
    double gout209 = 0;
    double gout210 = 0;
    double gout211 = 0;
    double gout212 = 0;
    double gout213 = 0;
    double gout214 = 0;
    double gout215 = 0;

    double xi = bas_x[ish];
    double yi = bas_y[ish];
    double zi = bas_z[ish];
    double ABx = xi - bas_x[jsh];
    double ABy = yi - bas_y[jsh];
    double ABz = zi - bas_z[jsh];
    double xk = bas_x[ksh];
    double yk = bas_y[ksh];
    double zk = bas_z[ksh];

    prim_ij0 = prim_ij;
    prim_ij1 = prim_ij + nprim_ij;
    prim_kl0 = prim_kl;
    prim_kl1 = prim_kl + nprim_kl;
    double rw[6];
    int irys;
    for (ij = prim_ij0; ij < prim_ij1; ++ij) {
        double alpha = i_exponent[ij];
        double beta = j_exponent[ij];
        double aij = a12[ij];
        double eij = e12[ij];
        double xij = x12[ij];
        double yij = y12[ij];
        double zij = z12[ij];
    for (kl = prim_kl0; kl < prim_kl1; ++kl) {
        double akl = a12[kl];
        double ekl = e12[kl];
        double xkl = x12[kl];
        double ykl = y12[kl];
        double zkl = z12[kl];
        double xijxkl = xij - xkl;
        double yijykl = yij - ykl;
        double zijzkl = zij - zkl;
        double aijkl = aij + akl;
        double a1 = aij * akl;
        double a0 = a1 / aijkl;
        double theta = omega > 0.0 ? omega * omega / (omega * omega + a0) : 1.0; 
        a0 *= theta;
        double x = a0 * (xijxkl * xijxkl + yijykl * yijykl + zijzkl * zijzkl);
        double fac = norm * eij * ekl * sqrt(a0 / (a1 * a1 * a1));
        //double fac = norm * eij * ekl / (sqrt(aijkl) * a1);

        GINTrys_root<3>(x, rw);
        GINTscale_u<3>(rw, theta);
      for (irys = 0; irys < 3; ++irys) {
            double weight0 = rw[irys+3] * fac;
            double root0 = rw[irys];
            double u2 = a0 * root0;
            double tmp4 = .5 / (u2 * aijkl + a1);
            double B00 = u2 * tmp4;
            double tmp1 = 2 * B00;
            double B10 = B00 + tmp4 * akl;
            double tmp2 = tmp1 * akl;
            double C00x = xij - xi - tmp2 * xijxkl;
            double C00y = yij - yi - tmp2 * yijykl;
            double C00z = zij - zi - tmp2 * zijzkl;
            double B01 = B00 + tmp4 * aij;
            double tmp3 = tmp1 * aij;
            double D00x = xkl - xk + tmp3 * xijxkl;
            double D00y = ykl - yk + tmp3 * yijykl;
            double D00z = zkl - zk + tmp3 * zijzkl;

            double g0 = B10+C00x*C00x;
            double g1 = 3*B10*C00x;
            double g2 = g1+C00x*C00x*C00x;
            double g3 = C00x*D00x;
            double g4 = B00+g3;
            double g5 = 2*B00*C00x;
            double g6 = g0*D00x;
            double g7 = g5+g6;
            double g8 = 3*B00*g0;
            double g9 = 3*B10;
            double g10 = g9+C00x*C00x;
            double g11 = C00x*g10*D00x;
            double g12 = g8+g11;
            double g13 = B01+D00x*D00x;
            double g14 = 2*B00*D00x;
            double g15 = C00x*g13;
            double g16 = g14+g15;
            double g17 = 2*B00*B00;
            double g20 = g17+(4*B00*C00x*D00x)+(g0*g13);
            double g21 = 6*B00*B00*C00x;
            double g22 = 6*B00*g0*D00x;
            double g23 = C00x*g10*g13;
            double g24 = g21+g22+g23;
            double g25 = ABx+C00x;
            double g27 = B10+(C00x*g25);
            double g29 = g1+C00x*C00x*C00x+(ABx*g0);
            double g31 = B00+(g25*D00x);
            double g33 = ABx+(2*C00x);
            double g36 = (B00*g33)+(g27*D00x);
            double g44 = (B00*(g9+(C00x*((2*ABx)+(3*C00x)))))+(g29*D00x);
            double g46 = g14+(g25*g13);
            double g49 = g17+(2*B00*g33*D00x)+(g27*g13);
            double g51 = g21+g22+g23+(ABx*g20);
            double g52 = B10+C00y*C00y;
            double g53 = 3*B10*C00y;
            double g54 = g53+C00y*C00y*C00y;
            double g56 = B00+(C00y*D00y);
            double g59 = (2*B00*C00y)+(g52*D00y);
            double g61 = g9+C00y*C00y;
            double g63 = (3*B00*g52)+(C00y*g61*D00y);
            double g64 = B01+D00y*D00y;
            double g65 = 2*B00*D00y;
            double g67 = g65+(C00y*g64);
            double g70 = g17+(4*B00*C00y*D00y)+(g52*g64);
            double g71 = 6*B00*B00*C00y;
            double g72 = 6*B00*g52*D00y;
            double g73 = C00y*g61*g64;
            double g74 = g71+g72+g73;
            double g75 = ABy+C00y;
            double g77 = B10+(C00y*g75);
            double g79 = g53+C00y*C00y*C00y+(ABy*g52);
            double g81 = B00+(g75*D00y);
            double g83 = ABy+(2*C00y);
            double g86 = (B00*g83)+(g77*D00y);
            double g94 = (B00*(g9+(C00y*((2*ABy)+(3*C00y)))))+(g79*D00y);
            double g96 = g65+(g75*g64);
            double g99 = g17+(2*B00*g83*D00y)+(g77*g64);
            double g101 = g71+g72+g73+(ABy*g70);
            double g102 = B10+C00z*C00z;
            double g103 = 3*B10*C00z;
            double g104 = g103+C00z*C00z*C00z;
            double g106 = B00+(C00z*D00z);
            double g109 = (2*B00*C00z)+(g102*D00z);
            double g111 = g9+C00z*C00z;
            double g113 = (3*B00*g102)+(C00z*g111*D00z);
            double g114 = B01+D00z*D00z;
            double g115 = 2*B00*D00z;
            double g117 = g115+(C00z*g114);
            double g120 = g17+(4*B00*C00z*D00z)+(g102*g114);
            double g121 = 6*B00*B00*C00z;
            double g122 = 6*B00*g102*D00z;
            double g123 = C00z*g111*g114;
            double g124 = g121+g122+g123;
            double g125 = ABz+C00z;
            double g127 = B10+(C00z*g125);
            double g129 = g103+C00z*C00z*C00z+(ABz*g102);
            double g131 = B00+(g125*D00z);
            double g133 = ABz+(2*C00z);
            double g136 = (B00*g133)+(g127*D00z);
            double g144 = (B00*(g9+(C00z*((2*ABz)+(3*C00z)))))+(g129*D00z);
            double g146 = g115+(g125*g114);
            double g149 = g17+(2*B00*g133*D00z)+(g127*g114);
            double g151 = g121+g122+g123+(ABz*g120);

            gout0 += (-2*g16 + 2*alpha*g24) * weight0;
            gout1 += (-2*g4 + 2*alpha*g12) * (D00y) * weight0;
            gout2 += (-2*g4 + 2*alpha*g12) * (D00z) * weight0;
            gout3 += (-2*C00x + 2*alpha*g2) * (g64) * weight0;
            gout4 += (-2*C00x + 2*alpha*g2) * (D00y) * (D00z) * weight0;
            gout5 += (-2*C00x + 2*alpha*g2) * (g114) * weight0;
            gout6 += (-g13 + 2*alpha*g20) * (C00y) * weight0;
            gout7 += (-D00x + 2*alpha*g7) * (g56) * weight0;
            gout8 += (-D00x + 2*alpha*g7) * (C00y) * (D00z) * weight0;
            gout9 += (-1 + 2*alpha*g0) * (g67) * weight0;
            gout10 += (-1 + 2*alpha*g0) * (g56) * (D00z) * weight0;
            gout11 += (-1 + 2*alpha*g0) * (C00y) * (g114) * weight0;
            gout12 += (-g13 + 2*alpha*g20) * (C00z) * weight0;
            gout13 += (-D00x + 2*alpha*g7) * (D00y) * (C00z) * weight0;
            gout14 += (-D00x + 2*alpha*g7) * (g106) * weight0;
            gout15 += (-1 + 2*alpha*g0) * (g64) * (C00z) * weight0;
            gout16 += (-1 + 2*alpha*g0) * (D00y) * (g106) * weight0;
            gout17 += (-1 + 2*alpha*g0) * (g117) * weight0;
            gout18 += (2*alpha*g16) * (g52) * weight0;
            gout19 += (2*alpha*g4) * (g59) * weight0;
            gout20 += (2*alpha*g4) * (g52) * (D00z) * weight0;
            gout21 += (2*alpha*C00x) * (g70) * weight0;
            gout22 += (2*alpha*C00x) * (g59) * (D00z) * weight0;
            gout23 += (2*alpha*C00x) * (g52) * (g114) * weight0;
            gout24 += (2*alpha*g16) * (C00y) * (C00z) * weight0;
            gout25 += (2*alpha*g4) * (g56) * (C00z) * weight0;
            gout26 += (2*alpha*g4) * (C00y) * (g106) * weight0;
            gout27 += (2*alpha*C00x) * (g67) * (C00z) * weight0;
            gout28 += (2*alpha*C00x) * (g56) * (g106) * weight0;
            gout29 += (2*alpha*C00x) * (C00y) * (g117) * weight0;
            gout30 += (2*alpha*g16) * (g102) * weight0;
            gout31 += (2*alpha*g4) * (D00y) * (g102) * weight0;
            gout32 += (2*alpha*g4) * (g109) * weight0;
            gout33 += (2*alpha*C00x) * (g64) * (g102) * weight0;
            gout34 += (2*alpha*C00x) * (D00y) * (g109) * weight0;
            gout35 += (2*alpha*C00x) * (g120) * weight0;
            gout36 += (g20) * (2*alpha*C00y) * weight0;
            gout37 += (g7) * (2*alpha*g56) * weight0;
            gout38 += (g7) * (2*alpha*C00y) * (D00z) * weight0;
            gout39 += (g0) * (2*alpha*g67) * weight0;
            gout40 += (g0) * (2*alpha*g56) * (D00z) * weight0;
            gout41 += (g0) * (2*alpha*C00y) * (g114) * weight0;
            gout42 += (g16) * (-1 + 2*alpha*g52) * weight0;
            gout43 += (g4) * (-D00y + 2*alpha*g59) * weight0;
            gout44 += (g4) * (-1 + 2*alpha*g52) * (D00z) * weight0;
            gout45 += (C00x) * (-g64 + 2*alpha*g70) * weight0;
            gout46 += (C00x) * (-D00y + 2*alpha*g59) * (D00z) * weight0;
            gout47 += (C00x) * (-1 + 2*alpha*g52) * (g114) * weight0;
            gout48 += (g16) * (2*alpha*C00y) * (C00z) * weight0;
            gout49 += (g4) * (2*alpha*g56) * (C00z) * weight0;
            gout50 += (g4) * (2*alpha*C00y) * (g106) * weight0;
            gout51 += (C00x) * (2*alpha*g67) * (C00z) * weight0;
            gout52 += (C00x) * (2*alpha*g56) * (g106) * weight0;
            gout53 += (C00x) * (2*alpha*C00y) * (g117) * weight0;
            gout54 += (g13) * (-2*C00y + 2*alpha*g54) * weight0;
            gout55 += (D00x) * (-2*g56 + 2*alpha*g63) * weight0;
            gout56 += (D00x) * (-2*C00y + 2*alpha*g54) * (D00z) * weight0;
            gout57 += (-2*g67 + 2*alpha*g74) * weight0;
            gout58 += (-2*g56 + 2*alpha*g63) * (D00z) * weight0;
            gout59 += (-2*C00y + 2*alpha*g54) * (g114) * weight0;
            gout60 += (g13) * (-1 + 2*alpha*g52) * (C00z) * weight0;
            gout61 += (D00x) * (-D00y + 2*alpha*g59) * (C00z) * weight0;
            gout62 += (D00x) * (-1 + 2*alpha*g52) * (g106) * weight0;
            gout63 += (-g64 + 2*alpha*g70) * (C00z) * weight0;
            gout64 += (-D00y + 2*alpha*g59) * (g106) * weight0;
            gout65 += (-1 + 2*alpha*g52) * (g117) * weight0;
            gout66 += (g13) * (2*alpha*C00y) * (g102) * weight0;
            gout67 += (D00x) * (2*alpha*g56) * (g102) * weight0;
            gout68 += (D00x) * (2*alpha*C00y) * (g109) * weight0;
            gout69 += (2*alpha*g67) * (g102) * weight0;
            gout70 += (2*alpha*g56) * (g109) * weight0;
            gout71 += (2*alpha*C00y) * (g120) * weight0;
            gout72 += (g20) * (2*alpha*C00z) * weight0;
            gout73 += (g7) * (D00y) * (2*alpha*C00z) * weight0;
            gout74 += (g7) * (2*alpha*g106) * weight0;
            gout75 += (g0) * (g64) * (2*alpha*C00z) * weight0;
            gout76 += (g0) * (D00y) * (2*alpha*g106) * weight0;
            gout77 += (g0) * (2*alpha*g117) * weight0;
            gout78 += (g16) * (C00y) * (2*alpha*C00z) * weight0;
            gout79 += (g4) * (g56) * (2*alpha*C00z) * weight0;
            gout80 += (g4) * (C00y) * (2*alpha*g106) * weight0;
            gout81 += (C00x) * (g67) * (2*alpha*C00z) * weight0;
            gout82 += (C00x) * (g56) * (2*alpha*g106) * weight0;
            gout83 += (C00x) * (C00y) * (2*alpha*g117) * weight0;
            gout84 += (g16) * (-1 + 2*alpha*g102) * weight0;
            gout85 += (g4) * (D00y) * (-1 + 2*alpha*g102) * weight0;
            gout86 += (g4) * (-D00z + 2*alpha*g109) * weight0;
            gout87 += (C00x) * (g64) * (-1 + 2*alpha*g102) * weight0;
            gout88 += (C00x) * (D00y) * (-D00z + 2*alpha*g109) * weight0;
            gout89 += (C00x) * (-g114 + 2*alpha*g120) * weight0;
            gout90 += (g13) * (g52) * (2*alpha*C00z) * weight0;
            gout91 += (D00x) * (g59) * (2*alpha*C00z) * weight0;
            gout92 += (D00x) * (g52) * (2*alpha*g106) * weight0;
            gout93 += (g70) * (2*alpha*C00z) * weight0;
            gout94 += (g59) * (2*alpha*g106) * weight0;
            gout95 += (g52) * (2*alpha*g117) * weight0;
            gout96 += (g13) * (C00y) * (-1 + 2*alpha*g102) * weight0;
            gout97 += (D00x) * (g56) * (-1 + 2*alpha*g102) * weight0;
            gout98 += (D00x) * (C00y) * (-D00z + 2*alpha*g109) * weight0;
            gout99 += (g67) * (-1 + 2*alpha*g102) * weight0;
            gout100 += (g56) * (-D00z + 2*alpha*g109) * weight0;
            gout101 += (C00y) * (-g114 + 2*alpha*g120) * weight0;
            gout102 += (g13) * (-2*C00z + 2*alpha*g104) * weight0;
            gout103 += (D00x) * (D00y) * (-2*C00z + 2*alpha*g104) * weight0;
            gout104 += (D00x) * (-2*g106 + 2*alpha*g113) * weight0;
            gout105 += (g64) * (-2*C00z + 2*alpha*g104) * weight0;
            gout106 += (D00y) * (-2*g106 + 2*alpha*g113) * weight0;
            gout107 += (-2*g117 + 2*alpha*g124) * weight0;
            gout108 += (2*beta*g51) * weight0;
            gout109 += (2*beta*g44) * (D00y) * weight0;
            gout110 += (2*beta*g44) * (D00z) * weight0;
            gout111 += (2*beta*g29) * (g64) * weight0;
            gout112 += (2*beta*g29) * (D00y) * (D00z) * weight0;
            gout113 += (2*beta*g29) * (g114) * weight0;
            gout114 += (2*beta*g49) * (C00y) * weight0;
            gout115 += (2*beta*g36) * (g56) * weight0;
            gout116 += (2*beta*g36) * (C00y) * (D00z) * weight0;
            gout117 += (2*beta*g27) * (g67) * weight0;
            gout118 += (2*beta*g27) * (g56) * (D00z) * weight0;
            gout119 += (2*beta*g27) * (C00y) * (g114) * weight0;
            gout120 += (2*beta*g49) * (C00z) * weight0;
            gout121 += (2*beta*g36) * (D00y) * (C00z) * weight0;
            gout122 += (2*beta*g36) * (g106) * weight0;
            gout123 += (2*beta*g27) * (g64) * (C00z) * weight0;
            gout124 += (2*beta*g27) * (D00y) * (g106) * weight0;
            gout125 += (2*beta*g27) * (g117) * weight0;
            gout126 += (2*beta*g46) * (g52) * weight0;
            gout127 += (2*beta*g31) * (g59) * weight0;
            gout128 += (2*beta*g31) * (g52) * (D00z) * weight0;
            gout129 += (2*beta*g25) * (g70) * weight0;
            gout130 += (2*beta*g25) * (g59) * (D00z) * weight0;
            gout131 += (2*beta*g25) * (g52) * (g114) * weight0;
            gout132 += (2*beta*g46) * (C00y) * (C00z) * weight0;
            gout133 += (2*beta*g31) * (g56) * (C00z) * weight0;
            gout134 += (2*beta*g31) * (C00y) * (g106) * weight0;
            gout135 += (2*beta*g25) * (g67) * (C00z) * weight0;
            gout136 += (2*beta*g25) * (g56) * (g106) * weight0;
            gout137 += (2*beta*g25) * (C00y) * (g117) * weight0;
            gout138 += (2*beta*g46) * (g102) * weight0;
            gout139 += (2*beta*g31) * (D00y) * (g102) * weight0;
            gout140 += (2*beta*g31) * (g109) * weight0;
            gout141 += (2*beta*g25) * (g64) * (g102) * weight0;
            gout142 += (2*beta*g25) * (D00y) * (g109) * weight0;
            gout143 += (2*beta*g25) * (g120) * weight0;
            gout144 += (g20) * (2*beta*g75) * weight0;
            gout145 += (g7) * (2*beta*g81) * weight0;
            gout146 += (g7) * (2*beta*g75) * (D00z) * weight0;
            gout147 += (g0) * (2*beta*g96) * weight0;
            gout148 += (g0) * (2*beta*g81) * (D00z) * weight0;
            gout149 += (g0) * (2*beta*g75) * (g114) * weight0;
            gout150 += (g16) * (2*beta*g77) * weight0;
            gout151 += (g4) * (2*beta*g86) * weight0;
            gout152 += (g4) * (2*beta*g77) * (D00z) * weight0;
            gout153 += (C00x) * (2*beta*g99) * weight0;
            gout154 += (C00x) * (2*beta*g86) * (D00z) * weight0;
            gout155 += (C00x) * (2*beta*g77) * (g114) * weight0;
            gout156 += (g16) * (2*beta*g75) * (C00z) * weight0;
            gout157 += (g4) * (2*beta*g81) * (C00z) * weight0;
            gout158 += (g4) * (2*beta*g75) * (g106) * weight0;
            gout159 += (C00x) * (2*beta*g96) * (C00z) * weight0;
            gout160 += (C00x) * (2*beta*g81) * (g106) * weight0;
            gout161 += (C00x) * (2*beta*g75) * (g117) * weight0;
            gout162 += (g13) * (2*beta*g79) * weight0;
            gout163 += (D00x) * (2*beta*g94) * weight0;
            gout164 += (D00x) * (2*beta*g79) * (D00z) * weight0;
            gout165 += (2*beta*g101) * weight0;
            gout166 += (2*beta*g94) * (D00z) * weight0;
            gout167 += (2*beta*g79) * (g114) * weight0;
            gout168 += (g13) * (2*beta*g77) * (C00z) * weight0;
            gout169 += (D00x) * (2*beta*g86) * (C00z) * weight0;
            gout170 += (D00x) * (2*beta*g77) * (g106) * weight0;
            gout171 += (2*beta*g99) * (C00z) * weight0;
            gout172 += (2*beta*g86) * (g106) * weight0;
            gout173 += (2*beta*g77) * (g117) * weight0;
            gout174 += (g13) * (2*beta*g75) * (g102) * weight0;
            gout175 += (D00x) * (2*beta*g81) * (g102) * weight0;
            gout176 += (D00x) * (2*beta*g75) * (g109) * weight0;
            gout177 += (2*beta*g96) * (g102) * weight0;
            gout178 += (2*beta*g81) * (g109) * weight0;
            gout179 += (2*beta*g75) * (g120) * weight0;
            gout180 += (g20) * (2*beta*g125) * weight0;
            gout181 += (g7) * (D00y) * (2*beta*g125) * weight0;
            gout182 += (g7) * (2*beta*g131) * weight0;
            gout183 += (g0) * (g64) * (2*beta*g125) * weight0;
            gout184 += (g0) * (D00y) * (2*beta*g131) * weight0;
            gout185 += (g0) * (2*beta*g146) * weight0;
            gout186 += (g16) * (C00y) * (2*beta*g125) * weight0;
            gout187 += (g4) * (g56) * (2*beta*g125) * weight0;
            gout188 += (g4) * (C00y) * (2*beta*g131) * weight0;
            gout189 += (C00x) * (g67) * (2*beta*g125) * weight0;
            gout190 += (C00x) * (g56) * (2*beta*g131) * weight0;
            gout191 += (C00x) * (C00y) * (2*beta*g146) * weight0;
            gout192 += (g16) * (2*beta*g127) * weight0;
            gout193 += (g4) * (D00y) * (2*beta*g127) * weight0;
            gout194 += (g4) * (2*beta*g136) * weight0;
            gout195 += (C00x) * (g64) * (2*beta*g127) * weight0;
            gout196 += (C00x) * (D00y) * (2*beta*g136) * weight0;
            gout197 += (C00x) * (2*beta*g149) * weight0;
            gout198 += (g13) * (g52) * (2*beta*g125) * weight0;
            gout199 += (D00x) * (g59) * (2*beta*g125) * weight0;
            gout200 += (D00x) * (g52) * (2*beta*g131) * weight0;
            gout201 += (g70) * (2*beta*g125) * weight0;
            gout202 += (g59) * (2*beta*g131) * weight0;
            gout203 += (g52) * (2*beta*g146) * weight0;
            gout204 += (g13) * (C00y) * (2*beta*g127) * weight0;
            gout205 += (D00x) * (g56) * (2*beta*g127) * weight0;
            gout206 += (D00x) * (C00y) * (2*beta*g136) * weight0;
            gout207 += (g67) * (2*beta*g127) * weight0;
            gout208 += (g56) * (2*beta*g136) * weight0;
            gout209 += (C00y) * (2*beta*g149) * weight0;
            gout210 += (g13) * (2*beta*g129) * weight0;
            gout211 += (D00x) * (D00y) * (2*beta*g129) * weight0;
            gout212 += (D00x) * (2*beta*g144) * weight0;
            gout213 += (g64) * (2*beta*g129) * weight0;
            gout214 += (D00y) * (2*beta*g144) * weight0;
            gout215 += (2*beta*g151) * weight0;
        }
    } }

    int *ao_loc = c_bpcache.ao_loc;
    int i0 = ao_loc[ish];
    int j0 = ao_loc[jsh];
    int k0 = ao_loc[ksh];
    int l0 = ao_loc[lsh];
    int n_dm = jk.n_dm;
    int nao = jk.nao;
    size_t nao2 = nao * nao;
    double* __restrict__ dm = jk.dm;
    double *vj = jk.vj;
    double *vk = jk.vk;
    double d_0, d_1, d_2, d_3, d_4, d_5, d_6, d_7, d_8, d_9, d_10, d_11, d_12, d_13, d_14, d_15, d_16, d_17, d_18, d_19, d_20, d_21, d_22, d_23, d_24, d_25, d_26, d_27, d_28, d_29, d_30, d_31, d_32, d_33, d_34, d_35;

    for (int i_dm = 0; i_dm < n_dm; ++i_dm) {
        if (vj != NULL) {
            d_0 = dm[(k0+0)+nao*(l0+0)];
            d_1 = dm[(k0+1)+nao*(l0+0)];
            d_2 = dm[(k0+2)+nao*(l0+0)];
            d_3 = dm[(k0+3)+nao*(l0+0)];
            d_4 = dm[(k0+4)+nao*(l0+0)];
            d_5 = dm[(k0+5)+nao*(l0+0)];
            atomicAdd(vj+(i0+0)+nao*(j0+0), gout0*d_0+gout1*d_1+gout2*d_2+gout3*d_3+gout4*d_4+gout5*d_5);
            atomicAdd(vj+(i0+1)+nao*(j0+0), gout6*d_0+gout7*d_1+gout8*d_2+gout9*d_3+gout10*d_4+gout11*d_5);
            atomicAdd(vj+(i0+2)+nao*(j0+0), gout12*d_0+gout13*d_1+gout14*d_2+gout15*d_3+gout16*d_4+gout17*d_5);
            atomicAdd(vj+(i0+3)+nao*(j0+0), gout18*d_0+gout19*d_1+gout20*d_2+gout21*d_3+gout22*d_4+gout23*d_5);
            atomicAdd(vj+(i0+4)+nao*(j0+0), gout24*d_0+gout25*d_1+gout26*d_2+gout27*d_3+gout28*d_4+gout29*d_5);
            atomicAdd(vj+(i0+5)+nao*(j0+0), gout30*d_0+gout31*d_1+gout32*d_2+gout33*d_3+gout34*d_4+gout35*d_5);
            atomicAdd(vj+(i0+0)+nao*(j0+0)+nao2, gout36*d_0+gout37*d_1+gout38*d_2+gout39*d_3+gout40*d_4+gout41*d_5);
            atomicAdd(vj+(i0+1)+nao*(j0+0)+nao2, gout42*d_0+gout43*d_1+gout44*d_2+gout45*d_3+gout46*d_4+gout47*d_5);
            atomicAdd(vj+(i0+2)+nao*(j0+0)+nao2, gout48*d_0+gout49*d_1+gout50*d_2+gout51*d_3+gout52*d_4+gout53*d_5);
            atomicAdd(vj+(i0+3)+nao*(j0+0)+nao2, gout54*d_0+gout55*d_1+gout56*d_2+gout57*d_3+gout58*d_4+gout59*d_5);
            atomicAdd(vj+(i0+4)+nao*(j0+0)+nao2, gout60*d_0+gout61*d_1+gout62*d_2+gout63*d_3+gout64*d_4+gout65*d_5);
            atomicAdd(vj+(i0+5)+nao*(j0+0)+nao2, gout66*d_0+gout67*d_1+gout68*d_2+gout69*d_3+gout70*d_4+gout71*d_5);
            atomicAdd(vj+(i0+0)+nao*(j0+0)+2*nao2, gout72*d_0+gout73*d_1+gout74*d_2+gout75*d_3+gout76*d_4+gout77*d_5);
            atomicAdd(vj+(i0+1)+nao*(j0+0)+2*nao2, gout78*d_0+gout79*d_1+gout80*d_2+gout81*d_3+gout82*d_4+gout83*d_5);
            atomicAdd(vj+(i0+2)+nao*(j0+0)+2*nao2, gout84*d_0+gout85*d_1+gout86*d_2+gout87*d_3+gout88*d_4+gout89*d_5);
            atomicAdd(vj+(i0+3)+nao*(j0+0)+2*nao2, gout90*d_0+gout91*d_1+gout92*d_2+gout93*d_3+gout94*d_4+gout95*d_5);
            atomicAdd(vj+(i0+4)+nao*(j0+0)+2*nao2, gout96*d_0+gout97*d_1+gout98*d_2+gout99*d_3+gout100*d_4+gout101*d_5);
            atomicAdd(vj+(i0+5)+nao*(j0+0)+2*nao2, gout102*d_0+gout103*d_1+gout104*d_2+gout105*d_3+gout106*d_4+gout107*d_5);
            atomicAdd(vj+nao*(i0+0)+(j0+0), gout108*d_0+gout109*d_1+gout110*d_2+gout111*d_3+gout112*d_4+gout113*d_5);
            atomicAdd(vj+nao*(i0+1)+(j0+0), gout114*d_0+gout115*d_1+gout116*d_2+gout117*d_3+gout118*d_4+gout119*d_5);
            atomicAdd(vj+nao*(i0+2)+(j0+0), gout120*d_0+gout121*d_1+gout122*d_2+gout123*d_3+gout124*d_4+gout125*d_5);
            atomicAdd(vj+nao*(i0+3)+(j0+0), gout126*d_0+gout127*d_1+gout128*d_2+gout129*d_3+gout130*d_4+gout131*d_5);
            atomicAdd(vj+nao*(i0+4)+(j0+0), gout132*d_0+gout133*d_1+gout134*d_2+gout135*d_3+gout136*d_4+gout137*d_5);
            atomicAdd(vj+nao*(i0+5)+(j0+0), gout138*d_0+gout139*d_1+gout140*d_2+gout141*d_3+gout142*d_4+gout143*d_5);
            atomicAdd(vj+nao*(i0+0)+(j0+0)+nao2, gout144*d_0+gout145*d_1+gout146*d_2+gout147*d_3+gout148*d_4+gout149*d_5);
            atomicAdd(vj+nao*(i0+1)+(j0+0)+nao2, gout150*d_0+gout151*d_1+gout152*d_2+gout153*d_3+gout154*d_4+gout155*d_5);
            atomicAdd(vj+nao*(i0+2)+(j0+0)+nao2, gout156*d_0+gout157*d_1+gout158*d_2+gout159*d_3+gout160*d_4+gout161*d_5);
            atomicAdd(vj+nao*(i0+3)+(j0+0)+nao2, gout162*d_0+gout163*d_1+gout164*d_2+gout165*d_3+gout166*d_4+gout167*d_5);
            atomicAdd(vj+nao*(i0+4)+(j0+0)+nao2, gout168*d_0+gout169*d_1+gout170*d_2+gout171*d_3+gout172*d_4+gout173*d_5);
            atomicAdd(vj+nao*(i0+5)+(j0+0)+nao2, gout174*d_0+gout175*d_1+gout176*d_2+gout177*d_3+gout178*d_4+gout179*d_5);
            atomicAdd(vj+nao*(i0+0)+(j0+0)+2*nao2, gout180*d_0+gout181*d_1+gout182*d_2+gout183*d_3+gout184*d_4+gout185*d_5);
            atomicAdd(vj+nao*(i0+1)+(j0+0)+2*nao2, gout186*d_0+gout187*d_1+gout188*d_2+gout189*d_3+gout190*d_4+gout191*d_5);
            atomicAdd(vj+nao*(i0+2)+(j0+0)+2*nao2, gout192*d_0+gout193*d_1+gout194*d_2+gout195*d_3+gout196*d_4+gout197*d_5);
            atomicAdd(vj+nao*(i0+3)+(j0+0)+2*nao2, gout198*d_0+gout199*d_1+gout200*d_2+gout201*d_3+gout202*d_4+gout203*d_5);
            atomicAdd(vj+nao*(i0+4)+(j0+0)+2*nao2, gout204*d_0+gout205*d_1+gout206*d_2+gout207*d_3+gout208*d_4+gout209*d_5);
            atomicAdd(vj+nao*(i0+5)+(j0+0)+2*nao2, gout210*d_0+gout211*d_1+gout212*d_2+gout213*d_3+gout214*d_4+gout215*d_5);
            vj += 3*nao2;
        }
        if (vk != NULL) {
            // ijkl, jk -> il
            d_0 = dm[(j0+0)+nao*(k0+0)];
            d_1 = dm[(j0+0)+nao*(k0+1)];
            d_2 = dm[(j0+0)+nao*(k0+2)];
            d_3 = dm[(j0+0)+nao*(k0+3)];
            d_4 = dm[(j0+0)+nao*(k0+4)];
            d_5 = dm[(j0+0)+nao*(k0+5)];
            atomicAdd(vk+(i0+0)+nao*(l0+0), gout0*d_0+gout1*d_1+gout2*d_2+gout3*d_3+gout4*d_4+gout5*d_5);
            atomicAdd(vk+(i0+1)+nao*(l0+0), gout6*d_0+gout7*d_1+gout8*d_2+gout9*d_3+gout10*d_4+gout11*d_5);
            atomicAdd(vk+(i0+2)+nao*(l0+0), gout12*d_0+gout13*d_1+gout14*d_2+gout15*d_3+gout16*d_4+gout17*d_5);
            atomicAdd(vk+(i0+3)+nao*(l0+0), gout18*d_0+gout19*d_1+gout20*d_2+gout21*d_3+gout22*d_4+gout23*d_5);
            atomicAdd(vk+(i0+4)+nao*(l0+0), gout24*d_0+gout25*d_1+gout26*d_2+gout27*d_3+gout28*d_4+gout29*d_5);
            atomicAdd(vk+(i0+5)+nao*(l0+0), gout30*d_0+gout31*d_1+gout32*d_2+gout33*d_3+gout34*d_4+gout35*d_5);
            atomicAdd(vk+(i0+0)+nao*(l0+0)+nao2, gout36*d_0+gout37*d_1+gout38*d_2+gout39*d_3+gout40*d_4+gout41*d_5);
            atomicAdd(vk+(i0+1)+nao*(l0+0)+nao2, gout42*d_0+gout43*d_1+gout44*d_2+gout45*d_3+gout46*d_4+gout47*d_5);
            atomicAdd(vk+(i0+2)+nao*(l0+0)+nao2, gout48*d_0+gout49*d_1+gout50*d_2+gout51*d_3+gout52*d_4+gout53*d_5);
            atomicAdd(vk+(i0+3)+nao*(l0+0)+nao2, gout54*d_0+gout55*d_1+gout56*d_2+gout57*d_3+gout58*d_4+gout59*d_5);
            atomicAdd(vk+(i0+4)+nao*(l0+0)+nao2, gout60*d_0+gout61*d_1+gout62*d_2+gout63*d_3+gout64*d_4+gout65*d_5);
            atomicAdd(vk+(i0+5)+nao*(l0+0)+nao2, gout66*d_0+gout67*d_1+gout68*d_2+gout69*d_3+gout70*d_4+gout71*d_5);
            atomicAdd(vk+(i0+0)+nao*(l0+0)+2*nao2, gout72*d_0+gout73*d_1+gout74*d_2+gout75*d_3+gout76*d_4+gout77*d_5);
            atomicAdd(vk+(i0+1)+nao*(l0+0)+2*nao2, gout78*d_0+gout79*d_1+gout80*d_2+gout81*d_3+gout82*d_4+gout83*d_5);
            atomicAdd(vk+(i0+2)+nao*(l0+0)+2*nao2, gout84*d_0+gout85*d_1+gout86*d_2+gout87*d_3+gout88*d_4+gout89*d_5);
            atomicAdd(vk+(i0+3)+nao*(l0+0)+2*nao2, gout90*d_0+gout91*d_1+gout92*d_2+gout93*d_3+gout94*d_4+gout95*d_5);
            atomicAdd(vk+(i0+4)+nao*(l0+0)+2*nao2, gout96*d_0+gout97*d_1+gout98*d_2+gout99*d_3+gout100*d_4+gout101*d_5);
            atomicAdd(vk+(i0+5)+nao*(l0+0)+2*nao2, gout102*d_0+gout103*d_1+gout104*d_2+gout105*d_3+gout106*d_4+gout107*d_5);
            // ijkl, jl -> ik
            d_0 = dm[(j0+0)+nao*(l0+0)];
            atomicAdd(vk+(i0+0)+nao*(k0+0), gout0*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+1), gout1*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+2), gout2*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+3), gout3*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+4), gout4*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+5), gout5*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+0), gout6*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+1), gout7*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+2), gout8*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+3), gout9*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+4), gout10*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+5), gout11*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+0), gout12*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+1), gout13*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+2), gout14*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+3), gout15*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+4), gout16*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+5), gout17*d_0);
            atomicAdd(vk+(i0+3)+nao*(k0+0), gout18*d_0);
            atomicAdd(vk+(i0+3)+nao*(k0+1), gout19*d_0);
            atomicAdd(vk+(i0+3)+nao*(k0+2), gout20*d_0);
            atomicAdd(vk+(i0+3)+nao*(k0+3), gout21*d_0);
            atomicAdd(vk+(i0+3)+nao*(k0+4), gout22*d_0);
            atomicAdd(vk+(i0+3)+nao*(k0+5), gout23*d_0);
            atomicAdd(vk+(i0+4)+nao*(k0+0), gout24*d_0);
            atomicAdd(vk+(i0+4)+nao*(k0+1), gout25*d_0);
            atomicAdd(vk+(i0+4)+nao*(k0+2), gout26*d_0);
            atomicAdd(vk+(i0+4)+nao*(k0+3), gout27*d_0);
            atomicAdd(vk+(i0+4)+nao*(k0+4), gout28*d_0);
            atomicAdd(vk+(i0+4)+nao*(k0+5), gout29*d_0);
            atomicAdd(vk+(i0+5)+nao*(k0+0), gout30*d_0);
            atomicAdd(vk+(i0+5)+nao*(k0+1), gout31*d_0);
            atomicAdd(vk+(i0+5)+nao*(k0+2), gout32*d_0);
            atomicAdd(vk+(i0+5)+nao*(k0+3), gout33*d_0);
            atomicAdd(vk+(i0+5)+nao*(k0+4), gout34*d_0);
            atomicAdd(vk+(i0+5)+nao*(k0+5), gout35*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+0)+nao2, gout36*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+1)+nao2, gout37*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+2)+nao2, gout38*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+3)+nao2, gout39*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+4)+nao2, gout40*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+5)+nao2, gout41*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+0)+nao2, gout42*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+1)+nao2, gout43*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+2)+nao2, gout44*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+3)+nao2, gout45*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+4)+nao2, gout46*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+5)+nao2, gout47*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+0)+nao2, gout48*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+1)+nao2, gout49*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+2)+nao2, gout50*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+3)+nao2, gout51*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+4)+nao2, gout52*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+5)+nao2, gout53*d_0);
            atomicAdd(vk+(i0+3)+nao*(k0+0)+nao2, gout54*d_0);
            atomicAdd(vk+(i0+3)+nao*(k0+1)+nao2, gout55*d_0);
            atomicAdd(vk+(i0+3)+nao*(k0+2)+nao2, gout56*d_0);
            atomicAdd(vk+(i0+3)+nao*(k0+3)+nao2, gout57*d_0);
            atomicAdd(vk+(i0+3)+nao*(k0+4)+nao2, gout58*d_0);
            atomicAdd(vk+(i0+3)+nao*(k0+5)+nao2, gout59*d_0);
            atomicAdd(vk+(i0+4)+nao*(k0+0)+nao2, gout60*d_0);
            atomicAdd(vk+(i0+4)+nao*(k0+1)+nao2, gout61*d_0);
            atomicAdd(vk+(i0+4)+nao*(k0+2)+nao2, gout62*d_0);
            atomicAdd(vk+(i0+4)+nao*(k0+3)+nao2, gout63*d_0);
            atomicAdd(vk+(i0+4)+nao*(k0+4)+nao2, gout64*d_0);
            atomicAdd(vk+(i0+4)+nao*(k0+5)+nao2, gout65*d_0);
            atomicAdd(vk+(i0+5)+nao*(k0+0)+nao2, gout66*d_0);
            atomicAdd(vk+(i0+5)+nao*(k0+1)+nao2, gout67*d_0);
            atomicAdd(vk+(i0+5)+nao*(k0+2)+nao2, gout68*d_0);
            atomicAdd(vk+(i0+5)+nao*(k0+3)+nao2, gout69*d_0);
            atomicAdd(vk+(i0+5)+nao*(k0+4)+nao2, gout70*d_0);
            atomicAdd(vk+(i0+5)+nao*(k0+5)+nao2, gout71*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+0)+2*nao2, gout72*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+1)+2*nao2, gout73*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+2)+2*nao2, gout74*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+3)+2*nao2, gout75*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+4)+2*nao2, gout76*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+5)+2*nao2, gout77*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+0)+2*nao2, gout78*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+1)+2*nao2, gout79*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+2)+2*nao2, gout80*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+3)+2*nao2, gout81*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+4)+2*nao2, gout82*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+5)+2*nao2, gout83*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+0)+2*nao2, gout84*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+1)+2*nao2, gout85*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+2)+2*nao2, gout86*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+3)+2*nao2, gout87*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+4)+2*nao2, gout88*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+5)+2*nao2, gout89*d_0);
            atomicAdd(vk+(i0+3)+nao*(k0+0)+2*nao2, gout90*d_0);
            atomicAdd(vk+(i0+3)+nao*(k0+1)+2*nao2, gout91*d_0);
            atomicAdd(vk+(i0+3)+nao*(k0+2)+2*nao2, gout92*d_0);
            atomicAdd(vk+(i0+3)+nao*(k0+3)+2*nao2, gout93*d_0);
            atomicAdd(vk+(i0+3)+nao*(k0+4)+2*nao2, gout94*d_0);
            atomicAdd(vk+(i0+3)+nao*(k0+5)+2*nao2, gout95*d_0);
            atomicAdd(vk+(i0+4)+nao*(k0+0)+2*nao2, gout96*d_0);
            atomicAdd(vk+(i0+4)+nao*(k0+1)+2*nao2, gout97*d_0);
            atomicAdd(vk+(i0+4)+nao*(k0+2)+2*nao2, gout98*d_0);
            atomicAdd(vk+(i0+4)+nao*(k0+3)+2*nao2, gout99*d_0);
            atomicAdd(vk+(i0+4)+nao*(k0+4)+2*nao2, gout100*d_0);
            atomicAdd(vk+(i0+4)+nao*(k0+5)+2*nao2, gout101*d_0);
            atomicAdd(vk+(i0+5)+nao*(k0+0)+2*nao2, gout102*d_0);
            atomicAdd(vk+(i0+5)+nao*(k0+1)+2*nao2, gout103*d_0);
            atomicAdd(vk+(i0+5)+nao*(k0+2)+2*nao2, gout104*d_0);
            atomicAdd(vk+(i0+5)+nao*(k0+3)+2*nao2, gout105*d_0);
            atomicAdd(vk+(i0+5)+nao*(k0+4)+2*nao2, gout106*d_0);
            atomicAdd(vk+(i0+5)+nao*(k0+5)+2*nao2, gout107*d_0);
            // ijkl, ik -> jl
            d_0 = dm[(i0+0)+nao*(k0+0)];
            d_1 = dm[(i0+0)+nao*(k0+1)];
            d_2 = dm[(i0+0)+nao*(k0+2)];
            d_3 = dm[(i0+0)+nao*(k0+3)];
            d_4 = dm[(i0+0)+nao*(k0+4)];
            d_5 = dm[(i0+0)+nao*(k0+5)];
            d_6 = dm[(i0+1)+nao*(k0+0)];
            d_7 = dm[(i0+1)+nao*(k0+1)];
            d_8 = dm[(i0+1)+nao*(k0+2)];
            d_9 = dm[(i0+1)+nao*(k0+3)];
            d_10 = dm[(i0+1)+nao*(k0+4)];
            d_11 = dm[(i0+1)+nao*(k0+5)];
            d_12 = dm[(i0+2)+nao*(k0+0)];
            d_13 = dm[(i0+2)+nao*(k0+1)];
            d_14 = dm[(i0+2)+nao*(k0+2)];
            d_15 = dm[(i0+2)+nao*(k0+3)];
            d_16 = dm[(i0+2)+nao*(k0+4)];
            d_17 = dm[(i0+2)+nao*(k0+5)];
            d_18 = dm[(i0+3)+nao*(k0+0)];
            d_19 = dm[(i0+3)+nao*(k0+1)];
            d_20 = dm[(i0+3)+nao*(k0+2)];
            d_21 = dm[(i0+3)+nao*(k0+3)];
            d_22 = dm[(i0+3)+nao*(k0+4)];
            d_23 = dm[(i0+3)+nao*(k0+5)];
            d_24 = dm[(i0+4)+nao*(k0+0)];
            d_25 = dm[(i0+4)+nao*(k0+1)];
            d_26 = dm[(i0+4)+nao*(k0+2)];
            d_27 = dm[(i0+4)+nao*(k0+3)];
            d_28 = dm[(i0+4)+nao*(k0+4)];
            d_29 = dm[(i0+4)+nao*(k0+5)];
            d_30 = dm[(i0+5)+nao*(k0+0)];
            d_31 = dm[(i0+5)+nao*(k0+1)];
            d_32 = dm[(i0+5)+nao*(k0+2)];
            d_33 = dm[(i0+5)+nao*(k0+3)];
            d_34 = dm[(i0+5)+nao*(k0+4)];
            d_35 = dm[(i0+5)+nao*(k0+5)];
            atomicAdd(vk+(j0+0)+nao*(l0+0), gout108*d_0+gout109*d_1+gout110*d_2+gout111*d_3+gout112*d_4+gout113*d_5+gout114*d_6+gout115*d_7+gout116*d_8+gout117*d_9+gout118*d_10+gout119*d_11+gout120*d_12+gout121*d_13+gout122*d_14+gout123*d_15+gout124*d_16+gout125*d_17+gout126*d_18+gout127*d_19+gout128*d_20+gout129*d_21+gout130*d_22+gout131*d_23+gout132*d_24+gout133*d_25+gout134*d_26+gout135*d_27+gout136*d_28+gout137*d_29+gout138*d_30+gout139*d_31+gout140*d_32+gout141*d_33+gout142*d_34+gout143*d_35);
            atomicAdd(vk+(j0+0)+nao*(l0+0)+nao2, gout144*d_0+gout145*d_1+gout146*d_2+gout147*d_3+gout148*d_4+gout149*d_5+gout150*d_6+gout151*d_7+gout152*d_8+gout153*d_9+gout154*d_10+gout155*d_11+gout156*d_12+gout157*d_13+gout158*d_14+gout159*d_15+gout160*d_16+gout161*d_17+gout162*d_18+gout163*d_19+gout164*d_20+gout165*d_21+gout166*d_22+gout167*d_23+gout168*d_24+gout169*d_25+gout170*d_26+gout171*d_27+gout172*d_28+gout173*d_29+gout174*d_30+gout175*d_31+gout176*d_32+gout177*d_33+gout178*d_34+gout179*d_35);
            atomicAdd(vk+(j0+0)+nao*(l0+0)+2*nao2, gout180*d_0+gout181*d_1+gout182*d_2+gout183*d_3+gout184*d_4+gout185*d_5+gout186*d_6+gout187*d_7+gout188*d_8+gout189*d_9+gout190*d_10+gout191*d_11+gout192*d_12+gout193*d_13+gout194*d_14+gout195*d_15+gout196*d_16+gout197*d_17+gout198*d_18+gout199*d_19+gout200*d_20+gout201*d_21+gout202*d_22+gout203*d_23+gout204*d_24+gout205*d_25+gout206*d_26+gout207*d_27+gout208*d_28+gout209*d_29+gout210*d_30+gout211*d_31+gout212*d_32+gout213*d_33+gout214*d_34+gout215*d_35);
            // ijkl, il -> jk
            d_0 = dm[(i0+0)+nao*(l0+0)];
            d_1 = dm[(i0+1)+nao*(l0+0)];
            d_2 = dm[(i0+2)+nao*(l0+0)];
            d_3 = dm[(i0+3)+nao*(l0+0)];
            d_4 = dm[(i0+4)+nao*(l0+0)];
            d_5 = dm[(i0+5)+nao*(l0+0)];
            atomicAdd(vk+(j0+0)+nao*(k0+0), gout108*d_0+gout114*d_1+gout120*d_2+gout126*d_3+gout132*d_4+gout138*d_5);
            atomicAdd(vk+(j0+0)+nao*(k0+1), gout109*d_0+gout115*d_1+gout121*d_2+gout127*d_3+gout133*d_4+gout139*d_5);
            atomicAdd(vk+(j0+0)+nao*(k0+2), gout110*d_0+gout116*d_1+gout122*d_2+gout128*d_3+gout134*d_4+gout140*d_5);
            atomicAdd(vk+(j0+0)+nao*(k0+3), gout111*d_0+gout117*d_1+gout123*d_2+gout129*d_3+gout135*d_4+gout141*d_5);
            atomicAdd(vk+(j0+0)+nao*(k0+4), gout112*d_0+gout118*d_1+gout124*d_2+gout130*d_3+gout136*d_4+gout142*d_5);
            atomicAdd(vk+(j0+0)+nao*(k0+5), gout113*d_0+gout119*d_1+gout125*d_2+gout131*d_3+gout137*d_4+gout143*d_5);
            atomicAdd(vk+(j0+0)+nao*(k0+0)+nao2, gout144*d_0+gout150*d_1+gout156*d_2+gout162*d_3+gout168*d_4+gout174*d_5);
            atomicAdd(vk+(j0+0)+nao*(k0+1)+nao2, gout145*d_0+gout151*d_1+gout157*d_2+gout163*d_3+gout169*d_4+gout175*d_5);
            atomicAdd(vk+(j0+0)+nao*(k0+2)+nao2, gout146*d_0+gout152*d_1+gout158*d_2+gout164*d_3+gout170*d_4+gout176*d_5);
            atomicAdd(vk+(j0+0)+nao*(k0+3)+nao2, gout147*d_0+gout153*d_1+gout159*d_2+gout165*d_3+gout171*d_4+gout177*d_5);
            atomicAdd(vk+(j0+0)+nao*(k0+4)+nao2, gout148*d_0+gout154*d_1+gout160*d_2+gout166*d_3+gout172*d_4+gout178*d_5);
            atomicAdd(vk+(j0+0)+nao*(k0+5)+nao2, gout149*d_0+gout155*d_1+gout161*d_2+gout167*d_3+gout173*d_4+gout179*d_5);
            atomicAdd(vk+(j0+0)+nao*(k0+0)+2*nao2, gout180*d_0+gout186*d_1+gout192*d_2+gout198*d_3+gout204*d_4+gout210*d_5);
            atomicAdd(vk+(j0+0)+nao*(k0+1)+2*nao2, gout181*d_0+gout187*d_1+gout193*d_2+gout199*d_3+gout205*d_4+gout211*d_5);
            atomicAdd(vk+(j0+0)+nao*(k0+2)+2*nao2, gout182*d_0+gout188*d_1+gout194*d_2+gout200*d_3+gout206*d_4+gout212*d_5);
            atomicAdd(vk+(j0+0)+nao*(k0+3)+2*nao2, gout183*d_0+gout189*d_1+gout195*d_2+gout201*d_3+gout207*d_4+gout213*d_5);
            atomicAdd(vk+(j0+0)+nao*(k0+4)+2*nao2, gout184*d_0+gout190*d_1+gout196*d_2+gout202*d_3+gout208*d_4+gout214*d_5);
            atomicAdd(vk+(j0+0)+nao*(k0+5)+2*nao2, gout185*d_0+gout191*d_1+gout197*d_2+gout203*d_3+gout209*d_4+gout215*d_5);
            vk += 3*nao2;
        }
        dm += nao2;
    }
}

__global__
static void GINTint2e_ip1_jk_kernel_2100(GINTEnvVars envs, JKMatrix jk,
                                    BasisProdOffsets offsets)
{
    int ntasks_ij = offsets.ntasks_ij;
    int ntasks_kl = offsets.ntasks_kl;
    int task_ij = blockIdx.x * blockDim.x + threadIdx.x;
    int task_kl = blockIdx.y * blockDim.y + threadIdx.y;
    if (task_ij >= ntasks_ij || task_kl >= ntasks_kl) {
        return;
    }
    int bas_ij = offsets.bas_ij + task_ij;
    int bas_kl = offsets.bas_kl + task_kl;
    double norm = envs.fac;
    double omega = envs.omega;
    int *bas_pair2bra = c_bpcache.bas_pair2bra;
    int *bas_pair2ket = c_bpcache.bas_pair2ket;
    int ish = bas_pair2bra[bas_ij];
    int jsh = bas_pair2ket[bas_ij];
    int ksh = bas_pair2bra[bas_kl];
    int lsh = bas_pair2ket[bas_kl];
    int nprim_ij = envs.nprim_ij;
    int nprim_kl = envs.nprim_kl;
    int prim_ij = offsets.primitive_ij + task_ij * nprim_ij;
    int prim_kl = offsets.primitive_kl + task_kl * nprim_kl;

    double* __restrict__ a12 = c_bpcache.a12;
    double* __restrict__ e12 = c_bpcache.e12;
    double* __restrict__ x12 = c_bpcache.x12;
    double* __restrict__ y12 = c_bpcache.y12;
    double* __restrict__ z12 = c_bpcache.z12;
    double * __restrict__ i_exponent = c_bpcache.a1;
    double * __restrict__ j_exponent = c_bpcache.a2;

    int ij, kl;
    int prim_ij0, prim_ij1, prim_kl0, prim_kl1;
    int nbas = c_bpcache.nbas;
    double* __restrict__ bas_x = c_bpcache.bas_coords;
    double* __restrict__ bas_y = bas_x + nbas;
    double* __restrict__ bas_z = bas_y + nbas;

    double gout0 = 0;
    double gout1 = 0;
    double gout2 = 0;
    double gout3 = 0;
    double gout4 = 0;
    double gout5 = 0;
    double gout6 = 0;
    double gout7 = 0;
    double gout8 = 0;
    double gout9 = 0;
    double gout10 = 0;
    double gout11 = 0;
    double gout12 = 0;
    double gout13 = 0;
    double gout14 = 0;
    double gout15 = 0;
    double gout16 = 0;
    double gout17 = 0;
    double gout18 = 0;
    double gout19 = 0;
    double gout20 = 0;
    double gout21 = 0;
    double gout22 = 0;
    double gout23 = 0;
    double gout24 = 0;
    double gout25 = 0;
    double gout26 = 0;
    double gout27 = 0;
    double gout28 = 0;
    double gout29 = 0;
    double gout30 = 0;
    double gout31 = 0;
    double gout32 = 0;
    double gout33 = 0;
    double gout34 = 0;
    double gout35 = 0;
    double gout36 = 0;
    double gout37 = 0;
    double gout38 = 0;
    double gout39 = 0;
    double gout40 = 0;
    double gout41 = 0;
    double gout42 = 0;
    double gout43 = 0;
    double gout44 = 0;
    double gout45 = 0;
    double gout46 = 0;
    double gout47 = 0;
    double gout48 = 0;
    double gout49 = 0;
    double gout50 = 0;
    double gout51 = 0;
    double gout52 = 0;
    double gout53 = 0;
    double gout54 = 0;
    double gout55 = 0;
    double gout56 = 0;
    double gout57 = 0;
    double gout58 = 0;
    double gout59 = 0;
    double gout60 = 0;
    double gout61 = 0;
    double gout62 = 0;
    double gout63 = 0;
    double gout64 = 0;
    double gout65 = 0;
    double gout66 = 0;
    double gout67 = 0;
    double gout68 = 0;
    double gout69 = 0;
    double gout70 = 0;
    double gout71 = 0;
    double gout72 = 0;
    double gout73 = 0;
    double gout74 = 0;
    double gout75 = 0;
    double gout76 = 0;
    double gout77 = 0;
    double gout78 = 0;
    double gout79 = 0;
    double gout80 = 0;
    double gout81 = 0;
    double gout82 = 0;
    double gout83 = 0;
    double gout84 = 0;
    double gout85 = 0;
    double gout86 = 0;
    double gout87 = 0;
    double gout88 = 0;
    double gout89 = 0;
    double gout90 = 0;
    double gout91 = 0;
    double gout92 = 0;
    double gout93 = 0;
    double gout94 = 0;
    double gout95 = 0;
    double gout96 = 0;
    double gout97 = 0;
    double gout98 = 0;
    double gout99 = 0;
    double gout100 = 0;
    double gout101 = 0;
    double gout102 = 0;
    double gout103 = 0;
    double gout104 = 0;
    double gout105 = 0;
    double gout106 = 0;
    double gout107 = 0;

    double xi = bas_x[ish];
    double yi = bas_y[ish];
    double zi = bas_z[ish];
    double ABx = xi - bas_x[jsh];
    double ABy = yi - bas_y[jsh];
    double ABz = zi - bas_z[jsh];


    prim_ij0 = prim_ij;
    prim_ij1 = prim_ij + nprim_ij;
    prim_kl0 = prim_kl;
    prim_kl1 = prim_kl + nprim_kl;
    double rw[6];
    int irys;
    for (ij = prim_ij0; ij < prim_ij1; ++ij) {
        double alpha = i_exponent[ij];
        double beta = j_exponent[ij];
        double aij = a12[ij];
        double eij = e12[ij];
        double xij = x12[ij];
        double yij = y12[ij];
        double zij = z12[ij];
    for (kl = prim_kl0; kl < prim_kl1; ++kl) {
        double akl = a12[kl];
        double ekl = e12[kl];
        double xkl = x12[kl];
        double ykl = y12[kl];
        double zkl = z12[kl];
        double xijxkl = xij - xkl;
        double yijykl = yij - ykl;
        double zijzkl = zij - zkl;
        double aijkl = aij + akl;
        double a1 = aij * akl;
        double a0 = a1 / aijkl;
        double theta = omega > 0.0 ? omega * omega / (omega * omega + a0) : 1.0; 
        a0 *= theta;
        double x = a0 * (xijxkl * xijxkl + yijykl * yijykl + zijzkl * zijzkl);
        double fac = norm * eij * ekl * sqrt(a0 / (a1 * a1 * a1));
        //double fac = norm * eij * ekl / (sqrt(aijkl) * a1);

        GINTrys_root<3>(x, rw);
        GINTscale_u<3>(rw, theta);
      for (irys = 0; irys < 3; ++irys) {
            double weight0 = rw[irys+3] * fac;
            double root0 = rw[irys];
            double u2 = a0 * root0;
            double tmp4 = .5 / (u2 * aijkl + a1);
            double B00 = u2 * tmp4;
            double tmp1 = 2 * B00;
            double B10 = B00 + tmp4 * akl;
            double tmp2 = tmp1 * akl;
            double C00x = xij - xi - tmp2 * xijxkl;
            double C00y = yij - yi - tmp2 * yijykl;
            double C00z = zij - zi - tmp2 * zijzkl;



            double g0 = B10+C00x*C00x;
            double g1 = 3*B10*C00x;
            double g2 = g1+C00x*C00x*C00x;
            double g3 = ABx+C00x;
            double g4 = C00x*g3;
            double g5 = B10+g4;
            double g6 = ABx*g0;
            double g7 = g1+C00x*C00x*C00x+g6;
            double g8 = 3*B10*B10;
            double g13 = g8+(C00x*C00x*C00x*g3)+(3*B10*C00x*(ABx+(2*C00x)));
            double g14 = B10+g3*g3;
            double g17 = (ABx*ABx*C00x)+g1+C00x*C00x*C00x+(2*ABx*g0);
            double g21 = g8+(6*B10*C00x*C00x)+C00x*C00x*C00x*C00x+(ABx*ABx*g0)+(2*ABx*g2);
            double g22 = B10+C00y*C00y;
            double g23 = 3*B10*C00y;
            double g24 = g23+C00y*C00y*C00y;
            double g25 = ABy+C00y;
            double g27 = B10+(C00y*g25);
            double g29 = g23+C00y*C00y*C00y+(ABy*g22);
            double g34 = g8+(C00y*C00y*C00y*g25)+(3*B10*C00y*(ABy+(2*C00y)));
            double g35 = B10+g25*g25;
            double g38 = (ABy*ABy*C00y)+g23+C00y*C00y*C00y+(2*ABy*g22);
            double g42 = g8+(6*B10*C00y*C00y)+C00y*C00y*C00y*C00y+(ABy*ABy*g22)+(2*ABy*g24);
            double g43 = B10+C00z*C00z;
            double g44 = 3*B10*C00z;
            double g45 = g44+C00z*C00z*C00z;
            double g46 = ABz+C00z;
            double g48 = B10+(C00z*g46);
            double g50 = g44+C00z*C00z*C00z+(ABz*g43);
            double g55 = g8+(C00z*C00z*C00z*g46)+(3*B10*C00z*(ABz+(2*C00z)));
            double g56 = B10+g46*g46;
            double g59 = (ABz*ABz*C00z)+g44+C00z*C00z*C00z+(2*ABz*g43);
            double g63 = g8+(6*B10*C00z*C00z)+C00z*C00z*C00z*C00z+(ABz*ABz*g43)+(2*ABz*g45);

            gout0 += (-2*g5 + 2*alpha*g13) * weight0;
            gout1 += (-2*C00x + 2*alpha*g2) * (g25) * weight0;
            gout2 += (-2*C00x + 2*alpha*g2) * (g46) * weight0;
            gout3 += (-g3 + 2*alpha*g7) * (C00y) * weight0;
            gout4 += (-1 + 2*alpha*g0) * (g27) * weight0;
            gout5 += (-1 + 2*alpha*g0) * (C00y) * (g46) * weight0;
            gout6 += (-g3 + 2*alpha*g7) * (C00z) * weight0;
            gout7 += (-1 + 2*alpha*g0) * (g25) * (C00z) * weight0;
            gout8 += (-1 + 2*alpha*g0) * (g48) * weight0;
            gout9 += (2*alpha*g5) * (g22) * weight0;
            gout10 += (2*alpha*C00x) * (g29) * weight0;
            gout11 += (2*alpha*C00x) * (g22) * (g46) * weight0;
            gout12 += (2*alpha*g5) * (C00y) * (C00z) * weight0;
            gout13 += (2*alpha*C00x) * (g27) * (C00z) * weight0;
            gout14 += (2*alpha*C00x) * (C00y) * (g48) * weight0;
            gout15 += (2*alpha*g5) * (g43) * weight0;
            gout16 += (2*alpha*C00x) * (g25) * (g43) * weight0;
            gout17 += (2*alpha*C00x) * (g50) * weight0;
            gout18 += (g7) * (2*alpha*C00y) * weight0;
            gout19 += (g0) * (2*alpha*g27) * weight0;
            gout20 += (g0) * (2*alpha*C00y) * (g46) * weight0;
            gout21 += (g5) * (-1 + 2*alpha*g22) * weight0;
            gout22 += (C00x) * (-g25 + 2*alpha*g29) * weight0;
            gout23 += (C00x) * (-1 + 2*alpha*g22) * (g46) * weight0;
            gout24 += (g5) * (2*alpha*C00y) * (C00z) * weight0;
            gout25 += (C00x) * (2*alpha*g27) * (C00z) * weight0;
            gout26 += (C00x) * (2*alpha*C00y) * (g48) * weight0;
            gout27 += (g3) * (-2*C00y + 2*alpha*g24) * weight0;
            gout28 += (-2*g27 + 2*alpha*g34) * weight0;
            gout29 += (-2*C00y + 2*alpha*g24) * (g46) * weight0;
            gout30 += (g3) * (-1 + 2*alpha*g22) * (C00z) * weight0;
            gout31 += (-g25 + 2*alpha*g29) * (C00z) * weight0;
            gout32 += (-1 + 2*alpha*g22) * (g48) * weight0;
            gout33 += (g3) * (2*alpha*C00y) * (g43) * weight0;
            gout34 += (2*alpha*g27) * (g43) * weight0;
            gout35 += (2*alpha*C00y) * (g50) * weight0;
            gout36 += (g7) * (2*alpha*C00z) * weight0;
            gout37 += (g0) * (g25) * (2*alpha*C00z) * weight0;
            gout38 += (g0) * (2*alpha*g48) * weight0;
            gout39 += (g5) * (C00y) * (2*alpha*C00z) * weight0;
            gout40 += (C00x) * (g27) * (2*alpha*C00z) * weight0;
            gout41 += (C00x) * (C00y) * (2*alpha*g48) * weight0;
            gout42 += (g5) * (-1 + 2*alpha*g43) * weight0;
            gout43 += (C00x) * (g25) * (-1 + 2*alpha*g43) * weight0;
            gout44 += (C00x) * (-g46 + 2*alpha*g50) * weight0;
            gout45 += (g3) * (g22) * (2*alpha*C00z) * weight0;
            gout46 += (g29) * (2*alpha*C00z) * weight0;
            gout47 += (g22) * (2*alpha*g48) * weight0;
            gout48 += (g3) * (C00y) * (-1 + 2*alpha*g43) * weight0;
            gout49 += (g27) * (-1 + 2*alpha*g43) * weight0;
            gout50 += (C00y) * (-g46 + 2*alpha*g50) * weight0;
            gout51 += (g3) * (-2*C00z + 2*alpha*g45) * weight0;
            gout52 += (g25) * (-2*C00z + 2*alpha*g45) * weight0;
            gout53 += (-2*g48 + 2*alpha*g55) * weight0;
            gout54 += (-g0 + 2*beta*g21) * weight0;
            gout55 += (2*beta*g7) * (g25) * weight0;
            gout56 += (2*beta*g7) * (g46) * weight0;
            gout57 += (-C00x + 2*beta*g17) * (C00y) * weight0;
            gout58 += (2*beta*g5) * (g27) * weight0;
            gout59 += (2*beta*g5) * (C00y) * (g46) * weight0;
            gout60 += (-C00x + 2*beta*g17) * (C00z) * weight0;
            gout61 += (2*beta*g5) * (g25) * (C00z) * weight0;
            gout62 += (2*beta*g5) * (g48) * weight0;
            gout63 += (-1 + 2*beta*g14) * (g22) * weight0;
            gout64 += (2*beta*g3) * (g29) * weight0;
            gout65 += (2*beta*g3) * (g22) * (g46) * weight0;
            gout66 += (-1 + 2*beta*g14) * (C00y) * (C00z) * weight0;
            gout67 += (2*beta*g3) * (g27) * (C00z) * weight0;
            gout68 += (2*beta*g3) * (C00y) * (g48) * weight0;
            gout69 += (-1 + 2*beta*g14) * (g43) * weight0;
            gout70 += (2*beta*g3) * (g25) * (g43) * weight0;
            gout71 += (2*beta*g3) * (g50) * weight0;
            gout72 += (g7) * (2*beta*g25) * weight0;
            gout73 += (g0) * (-1 + 2*beta*g35) * weight0;
            gout74 += (g0) * (2*beta*g25) * (g46) * weight0;
            gout75 += (g5) * (2*beta*g27) * weight0;
            gout76 += (C00x) * (-C00y + 2*beta*g38) * weight0;
            gout77 += (C00x) * (2*beta*g27) * (g46) * weight0;
            gout78 += (g5) * (2*beta*g25) * (C00z) * weight0;
            gout79 += (C00x) * (-1 + 2*beta*g35) * (C00z) * weight0;
            gout80 += (C00x) * (2*beta*g25) * (g48) * weight0;
            gout81 += (g3) * (2*beta*g29) * weight0;
            gout82 += (-g22 + 2*beta*g42) * weight0;
            gout83 += (2*beta*g29) * (g46) * weight0;
            gout84 += (g3) * (2*beta*g27) * (C00z) * weight0;
            gout85 += (-C00y + 2*beta*g38) * (C00z) * weight0;
            gout86 += (2*beta*g27) * (g48) * weight0;
            gout87 += (g3) * (2*beta*g25) * (g43) * weight0;
            gout88 += (-1 + 2*beta*g35) * (g43) * weight0;
            gout89 += (2*beta*g25) * (g50) * weight0;
            gout90 += (g7) * (2*beta*g46) * weight0;
            gout91 += (g0) * (g25) * (2*beta*g46) * weight0;
            gout92 += (g0) * (-1 + 2*beta*g56) * weight0;
            gout93 += (g5) * (C00y) * (2*beta*g46) * weight0;
            gout94 += (C00x) * (g27) * (2*beta*g46) * weight0;
            gout95 += (C00x) * (C00y) * (-1 + 2*beta*g56) * weight0;
            gout96 += (g5) * (2*beta*g48) * weight0;
            gout97 += (C00x) * (g25) * (2*beta*g48) * weight0;
            gout98 += (C00x) * (-C00z + 2*beta*g59) * weight0;
            gout99 += (g3) * (g22) * (2*beta*g46) * weight0;
            gout100 += (g29) * (2*beta*g46) * weight0;
            gout101 += (g22) * (-1 + 2*beta*g56) * weight0;
            gout102 += (g3) * (C00y) * (2*beta*g48) * weight0;
            gout103 += (g27) * (2*beta*g48) * weight0;
            gout104 += (C00y) * (-C00z + 2*beta*g59) * weight0;
            gout105 += (g3) * (2*beta*g50) * weight0;
            gout106 += (g25) * (2*beta*g50) * weight0;
            gout107 += (-g43 + 2*beta*g63) * weight0;
        }
    } }

    int *ao_loc = c_bpcache.ao_loc;
    int i0 = ao_loc[ish];
    int j0 = ao_loc[jsh];
    int k0 = ao_loc[ksh];
    int l0 = ao_loc[lsh];
    int n_dm = jk.n_dm;
    int nao = jk.nao;
    size_t nao2 = nao * nao;
    double* __restrict__ dm = jk.dm;
    double *vj = jk.vj;
    double *vk = jk.vk;
    double d_0, d_1, d_2, d_3, d_4, d_5;

    for (int i_dm = 0; i_dm < n_dm; ++i_dm) {
        if (vj != NULL) {
            d_0 = dm[(k0+0)+nao*(l0+0)];
            atomicAdd(vj+(i0+0)+nao*(j0+0), gout0*d_0);
            atomicAdd(vj+(i0+0)+nao*(j0+1), gout1*d_0);
            atomicAdd(vj+(i0+0)+nao*(j0+2), gout2*d_0);
            atomicAdd(vj+(i0+1)+nao*(j0+0), gout3*d_0);
            atomicAdd(vj+(i0+1)+nao*(j0+1), gout4*d_0);
            atomicAdd(vj+(i0+1)+nao*(j0+2), gout5*d_0);
            atomicAdd(vj+(i0+2)+nao*(j0+0), gout6*d_0);
            atomicAdd(vj+(i0+2)+nao*(j0+1), gout7*d_0);
            atomicAdd(vj+(i0+2)+nao*(j0+2), gout8*d_0);
            atomicAdd(vj+(i0+3)+nao*(j0+0), gout9*d_0);
            atomicAdd(vj+(i0+3)+nao*(j0+1), gout10*d_0);
            atomicAdd(vj+(i0+3)+nao*(j0+2), gout11*d_0);
            atomicAdd(vj+(i0+4)+nao*(j0+0), gout12*d_0);
            atomicAdd(vj+(i0+4)+nao*(j0+1), gout13*d_0);
            atomicAdd(vj+(i0+4)+nao*(j0+2), gout14*d_0);
            atomicAdd(vj+(i0+5)+nao*(j0+0), gout15*d_0);
            atomicAdd(vj+(i0+5)+nao*(j0+1), gout16*d_0);
            atomicAdd(vj+(i0+5)+nao*(j0+2), gout17*d_0);
            atomicAdd(vj+(i0+0)+nao*(j0+0)+nao2, gout18*d_0);
            atomicAdd(vj+(i0+0)+nao*(j0+1)+nao2, gout19*d_0);
            atomicAdd(vj+(i0+0)+nao*(j0+2)+nao2, gout20*d_0);
            atomicAdd(vj+(i0+1)+nao*(j0+0)+nao2, gout21*d_0);
            atomicAdd(vj+(i0+1)+nao*(j0+1)+nao2, gout22*d_0);
            atomicAdd(vj+(i0+1)+nao*(j0+2)+nao2, gout23*d_0);
            atomicAdd(vj+(i0+2)+nao*(j0+0)+nao2, gout24*d_0);
            atomicAdd(vj+(i0+2)+nao*(j0+1)+nao2, gout25*d_0);
            atomicAdd(vj+(i0+2)+nao*(j0+2)+nao2, gout26*d_0);
            atomicAdd(vj+(i0+3)+nao*(j0+0)+nao2, gout27*d_0);
            atomicAdd(vj+(i0+3)+nao*(j0+1)+nao2, gout28*d_0);
            atomicAdd(vj+(i0+3)+nao*(j0+2)+nao2, gout29*d_0);
            atomicAdd(vj+(i0+4)+nao*(j0+0)+nao2, gout30*d_0);
            atomicAdd(vj+(i0+4)+nao*(j0+1)+nao2, gout31*d_0);
            atomicAdd(vj+(i0+4)+nao*(j0+2)+nao2, gout32*d_0);
            atomicAdd(vj+(i0+5)+nao*(j0+0)+nao2, gout33*d_0);
            atomicAdd(vj+(i0+5)+nao*(j0+1)+nao2, gout34*d_0);
            atomicAdd(vj+(i0+5)+nao*(j0+2)+nao2, gout35*d_0);
            atomicAdd(vj+(i0+0)+nao*(j0+0)+2*nao2, gout36*d_0);
            atomicAdd(vj+(i0+0)+nao*(j0+1)+2*nao2, gout37*d_0);
            atomicAdd(vj+(i0+0)+nao*(j0+2)+2*nao2, gout38*d_0);
            atomicAdd(vj+(i0+1)+nao*(j0+0)+2*nao2, gout39*d_0);
            atomicAdd(vj+(i0+1)+nao*(j0+1)+2*nao2, gout40*d_0);
            atomicAdd(vj+(i0+1)+nao*(j0+2)+2*nao2, gout41*d_0);
            atomicAdd(vj+(i0+2)+nao*(j0+0)+2*nao2, gout42*d_0);
            atomicAdd(vj+(i0+2)+nao*(j0+1)+2*nao2, gout43*d_0);
            atomicAdd(vj+(i0+2)+nao*(j0+2)+2*nao2, gout44*d_0);
            atomicAdd(vj+(i0+3)+nao*(j0+0)+2*nao2, gout45*d_0);
            atomicAdd(vj+(i0+3)+nao*(j0+1)+2*nao2, gout46*d_0);
            atomicAdd(vj+(i0+3)+nao*(j0+2)+2*nao2, gout47*d_0);
            atomicAdd(vj+(i0+4)+nao*(j0+0)+2*nao2, gout48*d_0);
            atomicAdd(vj+(i0+4)+nao*(j0+1)+2*nao2, gout49*d_0);
            atomicAdd(vj+(i0+4)+nao*(j0+2)+2*nao2, gout50*d_0);
            atomicAdd(vj+(i0+5)+nao*(j0+0)+2*nao2, gout51*d_0);
            atomicAdd(vj+(i0+5)+nao*(j0+1)+2*nao2, gout52*d_0);
            atomicAdd(vj+(i0+5)+nao*(j0+2)+2*nao2, gout53*d_0);
            atomicAdd(vj+nao*(i0+0)+(j0+0), gout54*d_0);
            atomicAdd(vj+nao*(i0+0)+(j0+1), gout55*d_0);
            atomicAdd(vj+nao*(i0+0)+(j0+2), gout56*d_0);
            atomicAdd(vj+nao*(i0+1)+(j0+0), gout57*d_0);
            atomicAdd(vj+nao*(i0+1)+(j0+1), gout58*d_0);
            atomicAdd(vj+nao*(i0+1)+(j0+2), gout59*d_0);
            atomicAdd(vj+nao*(i0+2)+(j0+0), gout60*d_0);
            atomicAdd(vj+nao*(i0+2)+(j0+1), gout61*d_0);
            atomicAdd(vj+nao*(i0+2)+(j0+2), gout62*d_0);
            atomicAdd(vj+nao*(i0+3)+(j0+0), gout63*d_0);
            atomicAdd(vj+nao*(i0+3)+(j0+1), gout64*d_0);
            atomicAdd(vj+nao*(i0+3)+(j0+2), gout65*d_0);
            atomicAdd(vj+nao*(i0+4)+(j0+0), gout66*d_0);
            atomicAdd(vj+nao*(i0+4)+(j0+1), gout67*d_0);
            atomicAdd(vj+nao*(i0+4)+(j0+2), gout68*d_0);
            atomicAdd(vj+nao*(i0+5)+(j0+0), gout69*d_0);
            atomicAdd(vj+nao*(i0+5)+(j0+1), gout70*d_0);
            atomicAdd(vj+nao*(i0+5)+(j0+2), gout71*d_0);
            atomicAdd(vj+nao*(i0+0)+(j0+0)+nao2, gout72*d_0);
            atomicAdd(vj+nao*(i0+0)+(j0+1)+nao2, gout73*d_0);
            atomicAdd(vj+nao*(i0+0)+(j0+2)+nao2, gout74*d_0);
            atomicAdd(vj+nao*(i0+1)+(j0+0)+nao2, gout75*d_0);
            atomicAdd(vj+nao*(i0+1)+(j0+1)+nao2, gout76*d_0);
            atomicAdd(vj+nao*(i0+1)+(j0+2)+nao2, gout77*d_0);
            atomicAdd(vj+nao*(i0+2)+(j0+0)+nao2, gout78*d_0);
            atomicAdd(vj+nao*(i0+2)+(j0+1)+nao2, gout79*d_0);
            atomicAdd(vj+nao*(i0+2)+(j0+2)+nao2, gout80*d_0);
            atomicAdd(vj+nao*(i0+3)+(j0+0)+nao2, gout81*d_0);
            atomicAdd(vj+nao*(i0+3)+(j0+1)+nao2, gout82*d_0);
            atomicAdd(vj+nao*(i0+3)+(j0+2)+nao2, gout83*d_0);
            atomicAdd(vj+nao*(i0+4)+(j0+0)+nao2, gout84*d_0);
            atomicAdd(vj+nao*(i0+4)+(j0+1)+nao2, gout85*d_0);
            atomicAdd(vj+nao*(i0+4)+(j0+2)+nao2, gout86*d_0);
            atomicAdd(vj+nao*(i0+5)+(j0+0)+nao2, gout87*d_0);
            atomicAdd(vj+nao*(i0+5)+(j0+1)+nao2, gout88*d_0);
            atomicAdd(vj+nao*(i0+5)+(j0+2)+nao2, gout89*d_0);
            atomicAdd(vj+nao*(i0+0)+(j0+0)+2*nao2, gout90*d_0);
            atomicAdd(vj+nao*(i0+0)+(j0+1)+2*nao2, gout91*d_0);
            atomicAdd(vj+nao*(i0+0)+(j0+2)+2*nao2, gout92*d_0);
            atomicAdd(vj+nao*(i0+1)+(j0+0)+2*nao2, gout93*d_0);
            atomicAdd(vj+nao*(i0+1)+(j0+1)+2*nao2, gout94*d_0);
            atomicAdd(vj+nao*(i0+1)+(j0+2)+2*nao2, gout95*d_0);
            atomicAdd(vj+nao*(i0+2)+(j0+0)+2*nao2, gout96*d_0);
            atomicAdd(vj+nao*(i0+2)+(j0+1)+2*nao2, gout97*d_0);
            atomicAdd(vj+nao*(i0+2)+(j0+2)+2*nao2, gout98*d_0);
            atomicAdd(vj+nao*(i0+3)+(j0+0)+2*nao2, gout99*d_0);
            atomicAdd(vj+nao*(i0+3)+(j0+1)+2*nao2, gout100*d_0);
            atomicAdd(vj+nao*(i0+3)+(j0+2)+2*nao2, gout101*d_0);
            atomicAdd(vj+nao*(i0+4)+(j0+0)+2*nao2, gout102*d_0);
            atomicAdd(vj+nao*(i0+4)+(j0+1)+2*nao2, gout103*d_0);
            atomicAdd(vj+nao*(i0+4)+(j0+2)+2*nao2, gout104*d_0);
            atomicAdd(vj+nao*(i0+5)+(j0+0)+2*nao2, gout105*d_0);
            atomicAdd(vj+nao*(i0+5)+(j0+1)+2*nao2, gout106*d_0);
            atomicAdd(vj+nao*(i0+5)+(j0+2)+2*nao2, gout107*d_0);
            vj += 3*nao2;
        }
        if (vk != NULL) {
            // ijkl, jk -> il
            d_0 = dm[(j0+0)+nao*(k0+0)];
            d_1 = dm[(j0+1)+nao*(k0+0)];
            d_2 = dm[(j0+2)+nao*(k0+0)];
            atomicAdd(vk+(i0+0)+nao*(l0+0), gout0*d_0+gout1*d_1+gout2*d_2);
            atomicAdd(vk+(i0+1)+nao*(l0+0), gout3*d_0+gout4*d_1+gout5*d_2);
            atomicAdd(vk+(i0+2)+nao*(l0+0), gout6*d_0+gout7*d_1+gout8*d_2);
            atomicAdd(vk+(i0+3)+nao*(l0+0), gout9*d_0+gout10*d_1+gout11*d_2);
            atomicAdd(vk+(i0+4)+nao*(l0+0), gout12*d_0+gout13*d_1+gout14*d_2);
            atomicAdd(vk+(i0+5)+nao*(l0+0), gout15*d_0+gout16*d_1+gout17*d_2);
            atomicAdd(vk+(i0+0)+nao*(l0+0)+nao2, gout18*d_0+gout19*d_1+gout20*d_2);
            atomicAdd(vk+(i0+1)+nao*(l0+0)+nao2, gout21*d_0+gout22*d_1+gout23*d_2);
            atomicAdd(vk+(i0+2)+nao*(l0+0)+nao2, gout24*d_0+gout25*d_1+gout26*d_2);
            atomicAdd(vk+(i0+3)+nao*(l0+0)+nao2, gout27*d_0+gout28*d_1+gout29*d_2);
            atomicAdd(vk+(i0+4)+nao*(l0+0)+nao2, gout30*d_0+gout31*d_1+gout32*d_2);
            atomicAdd(vk+(i0+5)+nao*(l0+0)+nao2, gout33*d_0+gout34*d_1+gout35*d_2);
            atomicAdd(vk+(i0+0)+nao*(l0+0)+2*nao2, gout36*d_0+gout37*d_1+gout38*d_2);
            atomicAdd(vk+(i0+1)+nao*(l0+0)+2*nao2, gout39*d_0+gout40*d_1+gout41*d_2);
            atomicAdd(vk+(i0+2)+nao*(l0+0)+2*nao2, gout42*d_0+gout43*d_1+gout44*d_2);
            atomicAdd(vk+(i0+3)+nao*(l0+0)+2*nao2, gout45*d_0+gout46*d_1+gout47*d_2);
            atomicAdd(vk+(i0+4)+nao*(l0+0)+2*nao2, gout48*d_0+gout49*d_1+gout50*d_2);
            atomicAdd(vk+(i0+5)+nao*(l0+0)+2*nao2, gout51*d_0+gout52*d_1+gout53*d_2);
            // ijkl, jl -> ik
            d_0 = dm[(j0+0)+nao*(l0+0)];
            d_1 = dm[(j0+1)+nao*(l0+0)];
            d_2 = dm[(j0+2)+nao*(l0+0)];
            atomicAdd(vk+(i0+0)+nao*(k0+0), gout0*d_0+gout1*d_1+gout2*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+0), gout3*d_0+gout4*d_1+gout5*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+0), gout6*d_0+gout7*d_1+gout8*d_2);
            atomicAdd(vk+(i0+3)+nao*(k0+0), gout9*d_0+gout10*d_1+gout11*d_2);
            atomicAdd(vk+(i0+4)+nao*(k0+0), gout12*d_0+gout13*d_1+gout14*d_2);
            atomicAdd(vk+(i0+5)+nao*(k0+0), gout15*d_0+gout16*d_1+gout17*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+0)+nao2, gout18*d_0+gout19*d_1+gout20*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+0)+nao2, gout21*d_0+gout22*d_1+gout23*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+0)+nao2, gout24*d_0+gout25*d_1+gout26*d_2);
            atomicAdd(vk+(i0+3)+nao*(k0+0)+nao2, gout27*d_0+gout28*d_1+gout29*d_2);
            atomicAdd(vk+(i0+4)+nao*(k0+0)+nao2, gout30*d_0+gout31*d_1+gout32*d_2);
            atomicAdd(vk+(i0+5)+nao*(k0+0)+nao2, gout33*d_0+gout34*d_1+gout35*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+0)+2*nao2, gout36*d_0+gout37*d_1+gout38*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+0)+2*nao2, gout39*d_0+gout40*d_1+gout41*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+0)+2*nao2, gout42*d_0+gout43*d_1+gout44*d_2);
            atomicAdd(vk+(i0+3)+nao*(k0+0)+2*nao2, gout45*d_0+gout46*d_1+gout47*d_2);
            atomicAdd(vk+(i0+4)+nao*(k0+0)+2*nao2, gout48*d_0+gout49*d_1+gout50*d_2);
            atomicAdd(vk+(i0+5)+nao*(k0+0)+2*nao2, gout51*d_0+gout52*d_1+gout53*d_2);
            // ijkl, ik -> jl
            d_0 = dm[(i0+0)+nao*(k0+0)];
            d_1 = dm[(i0+1)+nao*(k0+0)];
            d_2 = dm[(i0+2)+nao*(k0+0)];
            d_3 = dm[(i0+3)+nao*(k0+0)];
            d_4 = dm[(i0+4)+nao*(k0+0)];
            d_5 = dm[(i0+5)+nao*(k0+0)];
            atomicAdd(vk+(j0+0)+nao*(l0+0), gout54*d_0+gout57*d_1+gout60*d_2+gout63*d_3+gout66*d_4+gout69*d_5);
            atomicAdd(vk+(j0+1)+nao*(l0+0), gout55*d_0+gout58*d_1+gout61*d_2+gout64*d_3+gout67*d_4+gout70*d_5);
            atomicAdd(vk+(j0+2)+nao*(l0+0), gout56*d_0+gout59*d_1+gout62*d_2+gout65*d_3+gout68*d_4+gout71*d_5);
            atomicAdd(vk+(j0+0)+nao*(l0+0)+nao2, gout72*d_0+gout75*d_1+gout78*d_2+gout81*d_3+gout84*d_4+gout87*d_5);
            atomicAdd(vk+(j0+1)+nao*(l0+0)+nao2, gout73*d_0+gout76*d_1+gout79*d_2+gout82*d_3+gout85*d_4+gout88*d_5);
            atomicAdd(vk+(j0+2)+nao*(l0+0)+nao2, gout74*d_0+gout77*d_1+gout80*d_2+gout83*d_3+gout86*d_4+gout89*d_5);
            atomicAdd(vk+(j0+0)+nao*(l0+0)+2*nao2, gout90*d_0+gout93*d_1+gout96*d_2+gout99*d_3+gout102*d_4+gout105*d_5);
            atomicAdd(vk+(j0+1)+nao*(l0+0)+2*nao2, gout91*d_0+gout94*d_1+gout97*d_2+gout100*d_3+gout103*d_4+gout106*d_5);
            atomicAdd(vk+(j0+2)+nao*(l0+0)+2*nao2, gout92*d_0+gout95*d_1+gout98*d_2+gout101*d_3+gout104*d_4+gout107*d_5);
            // ijkl, il -> jk
            d_0 = dm[(i0+0)+nao*(l0+0)];
            d_1 = dm[(i0+1)+nao*(l0+0)];
            d_2 = dm[(i0+2)+nao*(l0+0)];
            d_3 = dm[(i0+3)+nao*(l0+0)];
            d_4 = dm[(i0+4)+nao*(l0+0)];
            d_5 = dm[(i0+5)+nao*(l0+0)];
            atomicAdd(vk+(j0+0)+nao*(k0+0), gout54*d_0+gout57*d_1+gout60*d_2+gout63*d_3+gout66*d_4+gout69*d_5);
            atomicAdd(vk+(j0+1)+nao*(k0+0), gout55*d_0+gout58*d_1+gout61*d_2+gout64*d_3+gout67*d_4+gout70*d_5);
            atomicAdd(vk+(j0+2)+nao*(k0+0), gout56*d_0+gout59*d_1+gout62*d_2+gout65*d_3+gout68*d_4+gout71*d_5);
            atomicAdd(vk+(j0+0)+nao*(k0+0)+nao2, gout72*d_0+gout75*d_1+gout78*d_2+gout81*d_3+gout84*d_4+gout87*d_5);
            atomicAdd(vk+(j0+1)+nao*(k0+0)+nao2, gout73*d_0+gout76*d_1+gout79*d_2+gout82*d_3+gout85*d_4+gout88*d_5);
            atomicAdd(vk+(j0+2)+nao*(k0+0)+nao2, gout74*d_0+gout77*d_1+gout80*d_2+gout83*d_3+gout86*d_4+gout89*d_5);
            atomicAdd(vk+(j0+0)+nao*(k0+0)+2*nao2, gout90*d_0+gout93*d_1+gout96*d_2+gout99*d_3+gout102*d_4+gout105*d_5);
            atomicAdd(vk+(j0+1)+nao*(k0+0)+2*nao2, gout91*d_0+gout94*d_1+gout97*d_2+gout100*d_3+gout103*d_4+gout106*d_5);
            atomicAdd(vk+(j0+2)+nao*(k0+0)+2*nao2, gout92*d_0+gout95*d_1+gout98*d_2+gout101*d_3+gout104*d_4+gout107*d_5);
            vk += 3*nao2;
        }
        dm += nao2;
    }
}

__global__
static void GINTint2e_ip1_jk_kernel_2110(GINTEnvVars envs, JKMatrix jk,
                                    BasisProdOffsets offsets)
{
    int ntasks_ij = offsets.ntasks_ij;
    int ntasks_kl = offsets.ntasks_kl;
    int task_ij = blockIdx.x * blockDim.x + threadIdx.x;
    int task_kl = blockIdx.y * blockDim.y + threadIdx.y;
    if (task_ij >= ntasks_ij || task_kl >= ntasks_kl) {
        return;
    }
    int bas_ij = offsets.bas_ij + task_ij;
    int bas_kl = offsets.bas_kl + task_kl;
    double norm = envs.fac;
    double omega = envs.omega;
    int *bas_pair2bra = c_bpcache.bas_pair2bra;
    int *bas_pair2ket = c_bpcache.bas_pair2ket;
    int ish = bas_pair2bra[bas_ij];
    int jsh = bas_pair2ket[bas_ij];
    int ksh = bas_pair2bra[bas_kl];
    int lsh = bas_pair2ket[bas_kl];
    int nprim_ij = envs.nprim_ij;
    int nprim_kl = envs.nprim_kl;
    int prim_ij = offsets.primitive_ij + task_ij * nprim_ij;
    int prim_kl = offsets.primitive_kl + task_kl * nprim_kl;

    double* __restrict__ a12 = c_bpcache.a12;
    double* __restrict__ e12 = c_bpcache.e12;
    double* __restrict__ x12 = c_bpcache.x12;
    double* __restrict__ y12 = c_bpcache.y12;
    double* __restrict__ z12 = c_bpcache.z12;
    double * __restrict__ i_exponent = c_bpcache.a1;
    double * __restrict__ j_exponent = c_bpcache.a2;

    int ij, kl;
    int prim_ij0, prim_ij1, prim_kl0, prim_kl1;
    int nbas = c_bpcache.nbas;
    double* __restrict__ bas_x = c_bpcache.bas_coords;
    double* __restrict__ bas_y = bas_x + nbas;
    double* __restrict__ bas_z = bas_y + nbas;

    double gout0 = 0;
    double gout1 = 0;
    double gout2 = 0;
    double gout3 = 0;
    double gout4 = 0;
    double gout5 = 0;
    double gout6 = 0;
    double gout7 = 0;
    double gout8 = 0;
    double gout9 = 0;
    double gout10 = 0;
    double gout11 = 0;
    double gout12 = 0;
    double gout13 = 0;
    double gout14 = 0;
    double gout15 = 0;
    double gout16 = 0;
    double gout17 = 0;
    double gout18 = 0;
    double gout19 = 0;
    double gout20 = 0;
    double gout21 = 0;
    double gout22 = 0;
    double gout23 = 0;
    double gout24 = 0;
    double gout25 = 0;
    double gout26 = 0;
    double gout27 = 0;
    double gout28 = 0;
    double gout29 = 0;
    double gout30 = 0;
    double gout31 = 0;
    double gout32 = 0;
    double gout33 = 0;
    double gout34 = 0;
    double gout35 = 0;
    double gout36 = 0;
    double gout37 = 0;
    double gout38 = 0;
    double gout39 = 0;
    double gout40 = 0;
    double gout41 = 0;
    double gout42 = 0;
    double gout43 = 0;
    double gout44 = 0;
    double gout45 = 0;
    double gout46 = 0;
    double gout47 = 0;
    double gout48 = 0;
    double gout49 = 0;
    double gout50 = 0;
    double gout51 = 0;
    double gout52 = 0;
    double gout53 = 0;
    double gout54 = 0;
    double gout55 = 0;
    double gout56 = 0;
    double gout57 = 0;
    double gout58 = 0;
    double gout59 = 0;
    double gout60 = 0;
    double gout61 = 0;
    double gout62 = 0;
    double gout63 = 0;
    double gout64 = 0;
    double gout65 = 0;
    double gout66 = 0;
    double gout67 = 0;
    double gout68 = 0;
    double gout69 = 0;
    double gout70 = 0;
    double gout71 = 0;
    double gout72 = 0;
    double gout73 = 0;
    double gout74 = 0;
    double gout75 = 0;
    double gout76 = 0;
    double gout77 = 0;
    double gout78 = 0;
    double gout79 = 0;
    double gout80 = 0;
    double gout81 = 0;
    double gout82 = 0;
    double gout83 = 0;
    double gout84 = 0;
    double gout85 = 0;
    double gout86 = 0;
    double gout87 = 0;
    double gout88 = 0;
    double gout89 = 0;
    double gout90 = 0;
    double gout91 = 0;
    double gout92 = 0;
    double gout93 = 0;
    double gout94 = 0;
    double gout95 = 0;
    double gout96 = 0;
    double gout97 = 0;
    double gout98 = 0;
    double gout99 = 0;
    double gout100 = 0;
    double gout101 = 0;
    double gout102 = 0;
    double gout103 = 0;
    double gout104 = 0;
    double gout105 = 0;
    double gout106 = 0;
    double gout107 = 0;
    double gout108 = 0;
    double gout109 = 0;
    double gout110 = 0;
    double gout111 = 0;
    double gout112 = 0;
    double gout113 = 0;
    double gout114 = 0;
    double gout115 = 0;
    double gout116 = 0;
    double gout117 = 0;
    double gout118 = 0;
    double gout119 = 0;
    double gout120 = 0;
    double gout121 = 0;
    double gout122 = 0;
    double gout123 = 0;
    double gout124 = 0;
    double gout125 = 0;
    double gout126 = 0;
    double gout127 = 0;
    double gout128 = 0;
    double gout129 = 0;
    double gout130 = 0;
    double gout131 = 0;
    double gout132 = 0;
    double gout133 = 0;
    double gout134 = 0;
    double gout135 = 0;
    double gout136 = 0;
    double gout137 = 0;
    double gout138 = 0;
    double gout139 = 0;
    double gout140 = 0;
    double gout141 = 0;
    double gout142 = 0;
    double gout143 = 0;
    double gout144 = 0;
    double gout145 = 0;
    double gout146 = 0;
    double gout147 = 0;
    double gout148 = 0;
    double gout149 = 0;
    double gout150 = 0;
    double gout151 = 0;
    double gout152 = 0;
    double gout153 = 0;
    double gout154 = 0;
    double gout155 = 0;
    double gout156 = 0;
    double gout157 = 0;
    double gout158 = 0;
    double gout159 = 0;
    double gout160 = 0;
    double gout161 = 0;
    double gout162 = 0;
    double gout163 = 0;
    double gout164 = 0;
    double gout165 = 0;
    double gout166 = 0;
    double gout167 = 0;
    double gout168 = 0;
    double gout169 = 0;
    double gout170 = 0;
    double gout171 = 0;
    double gout172 = 0;
    double gout173 = 0;
    double gout174 = 0;
    double gout175 = 0;
    double gout176 = 0;
    double gout177 = 0;
    double gout178 = 0;
    double gout179 = 0;
    double gout180 = 0;
    double gout181 = 0;
    double gout182 = 0;
    double gout183 = 0;
    double gout184 = 0;
    double gout185 = 0;
    double gout186 = 0;
    double gout187 = 0;
    double gout188 = 0;
    double gout189 = 0;
    double gout190 = 0;
    double gout191 = 0;
    double gout192 = 0;
    double gout193 = 0;
    double gout194 = 0;
    double gout195 = 0;
    double gout196 = 0;
    double gout197 = 0;
    double gout198 = 0;
    double gout199 = 0;
    double gout200 = 0;
    double gout201 = 0;
    double gout202 = 0;
    double gout203 = 0;
    double gout204 = 0;
    double gout205 = 0;
    double gout206 = 0;
    double gout207 = 0;
    double gout208 = 0;
    double gout209 = 0;
    double gout210 = 0;
    double gout211 = 0;
    double gout212 = 0;
    double gout213 = 0;
    double gout214 = 0;
    double gout215 = 0;
    double gout216 = 0;
    double gout217 = 0;
    double gout218 = 0;
    double gout219 = 0;
    double gout220 = 0;
    double gout221 = 0;
    double gout222 = 0;
    double gout223 = 0;
    double gout224 = 0;
    double gout225 = 0;
    double gout226 = 0;
    double gout227 = 0;
    double gout228 = 0;
    double gout229 = 0;
    double gout230 = 0;
    double gout231 = 0;
    double gout232 = 0;
    double gout233 = 0;
    double gout234 = 0;
    double gout235 = 0;
    double gout236 = 0;
    double gout237 = 0;
    double gout238 = 0;
    double gout239 = 0;
    double gout240 = 0;
    double gout241 = 0;
    double gout242 = 0;
    double gout243 = 0;
    double gout244 = 0;
    double gout245 = 0;
    double gout246 = 0;
    double gout247 = 0;
    double gout248 = 0;
    double gout249 = 0;
    double gout250 = 0;
    double gout251 = 0;
    double gout252 = 0;
    double gout253 = 0;
    double gout254 = 0;
    double gout255 = 0;
    double gout256 = 0;
    double gout257 = 0;
    double gout258 = 0;
    double gout259 = 0;
    double gout260 = 0;
    double gout261 = 0;
    double gout262 = 0;
    double gout263 = 0;
    double gout264 = 0;
    double gout265 = 0;
    double gout266 = 0;
    double gout267 = 0;
    double gout268 = 0;
    double gout269 = 0;
    double gout270 = 0;
    double gout271 = 0;
    double gout272 = 0;
    double gout273 = 0;
    double gout274 = 0;
    double gout275 = 0;
    double gout276 = 0;
    double gout277 = 0;
    double gout278 = 0;
    double gout279 = 0;
    double gout280 = 0;
    double gout281 = 0;
    double gout282 = 0;
    double gout283 = 0;
    double gout284 = 0;
    double gout285 = 0;
    double gout286 = 0;
    double gout287 = 0;
    double gout288 = 0;
    double gout289 = 0;
    double gout290 = 0;
    double gout291 = 0;
    double gout292 = 0;
    double gout293 = 0;
    double gout294 = 0;
    double gout295 = 0;
    double gout296 = 0;
    double gout297 = 0;
    double gout298 = 0;
    double gout299 = 0;
    double gout300 = 0;
    double gout301 = 0;
    double gout302 = 0;
    double gout303 = 0;
    double gout304 = 0;
    double gout305 = 0;
    double gout306 = 0;
    double gout307 = 0;
    double gout308 = 0;
    double gout309 = 0;
    double gout310 = 0;
    double gout311 = 0;
    double gout312 = 0;
    double gout313 = 0;
    double gout314 = 0;
    double gout315 = 0;
    double gout316 = 0;
    double gout317 = 0;
    double gout318 = 0;
    double gout319 = 0;
    double gout320 = 0;
    double gout321 = 0;
    double gout322 = 0;
    double gout323 = 0;

    double xi = bas_x[ish];
    double yi = bas_y[ish];
    double zi = bas_z[ish];
    double ABx = xi - bas_x[jsh];
    double ABy = yi - bas_y[jsh];
    double ABz = zi - bas_z[jsh];
    double xk = bas_x[ksh];
    double yk = bas_y[ksh];
    double zk = bas_z[ksh];

    prim_ij0 = prim_ij;
    prim_ij1 = prim_ij + nprim_ij;
    prim_kl0 = prim_kl;
    prim_kl1 = prim_kl + nprim_kl;
    double rw[6];
    int irys;
    for (ij = prim_ij0; ij < prim_ij1; ++ij) {
        double alpha = i_exponent[ij];
        double beta = j_exponent[ij];
        double aij = a12[ij];
        double eij = e12[ij];
        double xij = x12[ij];
        double yij = y12[ij];
        double zij = z12[ij];
    for (kl = prim_kl0; kl < prim_kl1; ++kl) {
        double akl = a12[kl];
        double ekl = e12[kl];
        double xkl = x12[kl];
        double ykl = y12[kl];
        double zkl = z12[kl];
        double xijxkl = xij - xkl;
        double yijykl = yij - ykl;
        double zijzkl = zij - zkl;
        double aijkl = aij + akl;
        double a1 = aij * akl;
        double a0 = a1 / aijkl;
        double theta = omega > 0.0 ? omega * omega / (omega * omega + a0) : 1.0; 
        a0 *= theta;
        double x = a0 * (xijxkl * xijxkl + yijykl * yijykl + zijzkl * zijzkl);
        double fac = norm * eij * ekl * sqrt(a0 / (a1 * a1 * a1));
        //double fac = norm * eij * ekl / (sqrt(aijkl) * a1);

        GINTrys_root<3>(x, rw);
        GINTscale_u<3>(rw, theta);
      for (irys = 0; irys < 3; ++irys) {
            double weight0 = rw[irys+3] * fac;
            double root0 = rw[irys];
            double u2 = a0 * root0;
            double tmp4 = .5 / (u2 * aijkl + a1);
            double B00 = u2 * tmp4;
            double tmp1 = 2 * B00;
            double B10 = B00 + tmp4 * akl;
            double tmp2 = tmp1 * akl;
            double C00x = xij - xi - tmp2 * xijxkl;
            double C00y = yij - yi - tmp2 * yijykl;
            double C00z = zij - zi - tmp2 * zijzkl;

            double tmp3 = tmp1 * aij;
            double D00x = xkl - xk + tmp3 * xijxkl;
            double D00y = ykl - yk + tmp3 * yijykl;
            double D00z = zkl - zk + tmp3 * zijzkl;

            double g0 = B10+C00x*C00x;
            double g1 = 3*B10*C00x;
            double g2 = g1+C00x*C00x*C00x;
            double g3 = C00x*D00x;
            double g4 = B00+g3;
            double g5 = 2*B00*C00x;
            double g6 = g0*D00x;
            double g7 = g5+g6;
            double g8 = 3*B00*g0;
            double g9 = 3*B10;
            double g10 = g9+C00x*C00x;
            double g11 = C00x*g10*D00x;
            double g12 = g8+g11;
            double g13 = ABx+C00x;
            double g14 = C00x*g13;
            double g15 = B10+g14;
            double g16 = ABx*g0;
            double g17 = g1+C00x*C00x*C00x+g16;
            double g18 = 3*B10*B10;
            double g21 = ABx+(2*C00x);
            double g23 = g18+(C00x*C00x*C00x*g13)+(3*B10*C00x*g21);
            double g25 = B00+(g13*D00x);
            double g28 = (B00*g21)+(g15*D00x);
            double g36 = (B00*(g9+(C00x*((2*ABx)+(3*C00x)))))+(g17*D00x);
            double g40 = 6*B10*C00x*C00x;
            double g43 = (3*ABx*B00*g0)+(4*B00*g2)+(ABx*C00x*g10*D00x)+((g18+g40+C00x*C00x*C00x*C00x)*D00x);
            double g44 = B10+g13*g13;
            double g47 = (ABx*ABx*C00x)+g1+C00x*C00x*C00x+(2*ABx*g0);
            double g50 = g18+g40+C00x*C00x*C00x*C00x+(ABx*ABx*g0)+(2*ABx*g2);
            double g53 = (2*B00*g13)+(g44*D00x);
            double g57 = (4*ABx*B00*C00x)+g8+(2*ABx*g0*D00x)+g11+(ABx*ABx*g4);
            double g61 = (2*B00*g21*(g9+g14))+(g50*D00x);
            double g62 = B10+C00y*C00y;
            double g63 = 3*B10*C00y;
            double g64 = g63+C00y*C00y*C00y;
            double g66 = B00+(C00y*D00y);
            double g69 = (2*B00*C00y)+(g62*D00y);
            double g70 = 3*B00*g62;
            double g71 = g9+C00y*C00y;
            double g72 = C00y*g71*D00y;
            double g73 = g70+g72;
            double g74 = ABy+C00y;
            double g75 = C00y*g74;
            double g76 = B10+g75;
            double g78 = g63+C00y*C00y*C00y+(ABy*g62);
            double g81 = ABy+(2*C00y);
            double g83 = g18+(C00y*C00y*C00y*g74)+(3*B10*C00y*g81);
            double g85 = B00+(g74*D00y);
            double g88 = (B00*g81)+(g76*D00y);
            double g96 = (B00*(g9+(C00y*((2*ABy)+(3*C00y)))))+(g78*D00y);
            double g100 = 6*B10*C00y*C00y;
            double g103 = (3*ABy*B00*g62)+(4*B00*g64)+(ABy*C00y*g71*D00y)+((g18+g100+C00y*C00y*C00y*C00y)*D00y);
            double g104 = B10+g74*g74;
            double g107 = (ABy*ABy*C00y)+g63+C00y*C00y*C00y+(2*ABy*g62);
            double g110 = g18+g100+C00y*C00y*C00y*C00y+(ABy*ABy*g62)+(2*ABy*g64);
            double g113 = (2*B00*g74)+(g104*D00y);
            double g117 = (4*ABy*B00*C00y)+g70+(2*ABy*g62*D00y)+g72+(ABy*ABy*g66);
            double g121 = (2*B00*g81*(g9+g75))+(g110*D00y);
            double g122 = B10+C00z*C00z;
            double g123 = 3*B10*C00z;
            double g124 = g123+C00z*C00z*C00z;
            double g126 = B00+(C00z*D00z);
            double g129 = (2*B00*C00z)+(g122*D00z);
            double g130 = 3*B00*g122;
            double g131 = g9+C00z*C00z;
            double g132 = C00z*g131*D00z;
            double g133 = g130+g132;
            double g134 = ABz+C00z;
            double g135 = C00z*g134;
            double g136 = B10+g135;
            double g138 = g123+C00z*C00z*C00z+(ABz*g122);
            double g141 = ABz+(2*C00z);
            double g143 = g18+(C00z*C00z*C00z*g134)+(3*B10*C00z*g141);
            double g145 = B00+(g134*D00z);
            double g148 = (B00*g141)+(g136*D00z);
            double g156 = (B00*(g9+(C00z*((2*ABz)+(3*C00z)))))+(g138*D00z);
            double g160 = 6*B10*C00z*C00z;
            double g163 = (3*ABz*B00*g122)+(4*B00*g124)+(ABz*C00z*g131*D00z)+((g18+g160+C00z*C00z*C00z*C00z)*D00z);
            double g164 = B10+g134*g134;
            double g167 = (ABz*ABz*C00z)+g123+C00z*C00z*C00z+(2*ABz*g122);
            double g170 = g18+g160+C00z*C00z*C00z*C00z+(ABz*ABz*g122)+(2*ABz*g124);
            double g173 = (2*B00*g134)+(g164*D00z);
            double g177 = (4*ABz*B00*C00z)+g130+(2*ABz*g122*D00z)+g132+(ABz*ABz*g126);
            double g181 = (2*B00*g141*(g9+g135))+(g170*D00z);

            gout0 += (-2*g28 + 2*alpha*g43) * weight0;
            gout1 += (-2*g15 + 2*alpha*g23) * (D00y) * weight0;
            gout2 += (-2*g15 + 2*alpha*g23) * (D00z) * weight0;
            gout3 += (-2*g4 + 2*alpha*g12) * (g74) * weight0;
            gout4 += (-2*C00x + 2*alpha*g2) * (g85) * weight0;
            gout5 += (-2*C00x + 2*alpha*g2) * (g74) * (D00z) * weight0;
            gout6 += (-2*g4 + 2*alpha*g12) * (g134) * weight0;
            gout7 += (-2*C00x + 2*alpha*g2) * (D00y) * (g134) * weight0;
            gout8 += (-2*C00x + 2*alpha*g2) * (g145) * weight0;
            gout9 += (-g25 + 2*alpha*g36) * (C00y) * weight0;
            gout10 += (-g13 + 2*alpha*g17) * (g66) * weight0;
            gout11 += (-g13 + 2*alpha*g17) * (C00y) * (D00z) * weight0;
            gout12 += (-D00x + 2*alpha*g7) * (g76) * weight0;
            gout13 += (-1 + 2*alpha*g0) * (g88) * weight0;
            gout14 += (-1 + 2*alpha*g0) * (g76) * (D00z) * weight0;
            gout15 += (-D00x + 2*alpha*g7) * (C00y) * (g134) * weight0;
            gout16 += (-1 + 2*alpha*g0) * (g66) * (g134) * weight0;
            gout17 += (-1 + 2*alpha*g0) * (C00y) * (g145) * weight0;
            gout18 += (-g25 + 2*alpha*g36) * (C00z) * weight0;
            gout19 += (-g13 + 2*alpha*g17) * (D00y) * (C00z) * weight0;
            gout20 += (-g13 + 2*alpha*g17) * (g126) * weight0;
            gout21 += (-D00x + 2*alpha*g7) * (g74) * (C00z) * weight0;
            gout22 += (-1 + 2*alpha*g0) * (g85) * (C00z) * weight0;
            gout23 += (-1 + 2*alpha*g0) * (g74) * (g126) * weight0;
            gout24 += (-D00x + 2*alpha*g7) * (g136) * weight0;
            gout25 += (-1 + 2*alpha*g0) * (D00y) * (g136) * weight0;
            gout26 += (-1 + 2*alpha*g0) * (g148) * weight0;
            gout27 += (2*alpha*g28) * (g62) * weight0;
            gout28 += (2*alpha*g15) * (g69) * weight0;
            gout29 += (2*alpha*g15) * (g62) * (D00z) * weight0;
            gout30 += (2*alpha*g4) * (g78) * weight0;
            gout31 += (2*alpha*C00x) * (g96) * weight0;
            gout32 += (2*alpha*C00x) * (g78) * (D00z) * weight0;
            gout33 += (2*alpha*g4) * (g62) * (g134) * weight0;
            gout34 += (2*alpha*C00x) * (g69) * (g134) * weight0;
            gout35 += (2*alpha*C00x) * (g62) * (g145) * weight0;
            gout36 += (2*alpha*g28) * (C00y) * (C00z) * weight0;
            gout37 += (2*alpha*g15) * (g66) * (C00z) * weight0;
            gout38 += (2*alpha*g15) * (C00y) * (g126) * weight0;
            gout39 += (2*alpha*g4) * (g76) * (C00z) * weight0;
            gout40 += (2*alpha*C00x) * (g88) * (C00z) * weight0;
            gout41 += (2*alpha*C00x) * (g76) * (g126) * weight0;
            gout42 += (2*alpha*g4) * (C00y) * (g136) * weight0;
            gout43 += (2*alpha*C00x) * (g66) * (g136) * weight0;
            gout44 += (2*alpha*C00x) * (C00y) * (g148) * weight0;
            gout45 += (2*alpha*g28) * (g122) * weight0;
            gout46 += (2*alpha*g15) * (D00y) * (g122) * weight0;
            gout47 += (2*alpha*g15) * (g129) * weight0;
            gout48 += (2*alpha*g4) * (g74) * (g122) * weight0;
            gout49 += (2*alpha*C00x) * (g85) * (g122) * weight0;
            gout50 += (2*alpha*C00x) * (g74) * (g129) * weight0;
            gout51 += (2*alpha*g4) * (g138) * weight0;
            gout52 += (2*alpha*C00x) * (D00y) * (g138) * weight0;
            gout53 += (2*alpha*C00x) * (g156) * weight0;
            gout54 += (g36) * (2*alpha*C00y) * weight0;
            gout55 += (g17) * (2*alpha*g66) * weight0;
            gout56 += (g17) * (2*alpha*C00y) * (D00z) * weight0;
            gout57 += (g7) * (2*alpha*g76) * weight0;
            gout58 += (g0) * (2*alpha*g88) * weight0;
            gout59 += (g0) * (2*alpha*g76) * (D00z) * weight0;
            gout60 += (g7) * (2*alpha*C00y) * (g134) * weight0;
            gout61 += (g0) * (2*alpha*g66) * (g134) * weight0;
            gout62 += (g0) * (2*alpha*C00y) * (g145) * weight0;
            gout63 += (g28) * (-1 + 2*alpha*g62) * weight0;
            gout64 += (g15) * (-D00y + 2*alpha*g69) * weight0;
            gout65 += (g15) * (-1 + 2*alpha*g62) * (D00z) * weight0;
            gout66 += (g4) * (-g74 + 2*alpha*g78) * weight0;
            gout67 += (C00x) * (-g85 + 2*alpha*g96) * weight0;
            gout68 += (C00x) * (-g74 + 2*alpha*g78) * (D00z) * weight0;
            gout69 += (g4) * (-1 + 2*alpha*g62) * (g134) * weight0;
            gout70 += (C00x) * (-D00y + 2*alpha*g69) * (g134) * weight0;
            gout71 += (C00x) * (-1 + 2*alpha*g62) * (g145) * weight0;
            gout72 += (g28) * (2*alpha*C00y) * (C00z) * weight0;
            gout73 += (g15) * (2*alpha*g66) * (C00z) * weight0;
            gout74 += (g15) * (2*alpha*C00y) * (g126) * weight0;
            gout75 += (g4) * (2*alpha*g76) * (C00z) * weight0;
            gout76 += (C00x) * (2*alpha*g88) * (C00z) * weight0;
            gout77 += (C00x) * (2*alpha*g76) * (g126) * weight0;
            gout78 += (g4) * (2*alpha*C00y) * (g136) * weight0;
            gout79 += (C00x) * (2*alpha*g66) * (g136) * weight0;
            gout80 += (C00x) * (2*alpha*C00y) * (g148) * weight0;
            gout81 += (g25) * (-2*C00y + 2*alpha*g64) * weight0;
            gout82 += (g13) * (-2*g66 + 2*alpha*g73) * weight0;
            gout83 += (g13) * (-2*C00y + 2*alpha*g64) * (D00z) * weight0;
            gout84 += (D00x) * (-2*g76 + 2*alpha*g83) * weight0;
            gout85 += (-2*g88 + 2*alpha*g103) * weight0;
            gout86 += (-2*g76 + 2*alpha*g83) * (D00z) * weight0;
            gout87 += (D00x) * (-2*C00y + 2*alpha*g64) * (g134) * weight0;
            gout88 += (-2*g66 + 2*alpha*g73) * (g134) * weight0;
            gout89 += (-2*C00y + 2*alpha*g64) * (g145) * weight0;
            gout90 += (g25) * (-1 + 2*alpha*g62) * (C00z) * weight0;
            gout91 += (g13) * (-D00y + 2*alpha*g69) * (C00z) * weight0;
            gout92 += (g13) * (-1 + 2*alpha*g62) * (g126) * weight0;
            gout93 += (D00x) * (-g74 + 2*alpha*g78) * (C00z) * weight0;
            gout94 += (-g85 + 2*alpha*g96) * (C00z) * weight0;
            gout95 += (-g74 + 2*alpha*g78) * (g126) * weight0;
            gout96 += (D00x) * (-1 + 2*alpha*g62) * (g136) * weight0;
            gout97 += (-D00y + 2*alpha*g69) * (g136) * weight0;
            gout98 += (-1 + 2*alpha*g62) * (g148) * weight0;
            gout99 += (g25) * (2*alpha*C00y) * (g122) * weight0;
            gout100 += (g13) * (2*alpha*g66) * (g122) * weight0;
            gout101 += (g13) * (2*alpha*C00y) * (g129) * weight0;
            gout102 += (D00x) * (2*alpha*g76) * (g122) * weight0;
            gout103 += (2*alpha*g88) * (g122) * weight0;
            gout104 += (2*alpha*g76) * (g129) * weight0;
            gout105 += (D00x) * (2*alpha*C00y) * (g138) * weight0;
            gout106 += (2*alpha*g66) * (g138) * weight0;
            gout107 += (2*alpha*C00y) * (g156) * weight0;
            gout108 += (g36) * (2*alpha*C00z) * weight0;
            gout109 += (g17) * (D00y) * (2*alpha*C00z) * weight0;
            gout110 += (g17) * (2*alpha*g126) * weight0;
            gout111 += (g7) * (g74) * (2*alpha*C00z) * weight0;
            gout112 += (g0) * (g85) * (2*alpha*C00z) * weight0;
            gout113 += (g0) * (g74) * (2*alpha*g126) * weight0;
            gout114 += (g7) * (2*alpha*g136) * weight0;
            gout115 += (g0) * (D00y) * (2*alpha*g136) * weight0;
            gout116 += (g0) * (2*alpha*g148) * weight0;
            gout117 += (g28) * (C00y) * (2*alpha*C00z) * weight0;
            gout118 += (g15) * (g66) * (2*alpha*C00z) * weight0;
            gout119 += (g15) * (C00y) * (2*alpha*g126) * weight0;
            gout120 += (g4) * (g76) * (2*alpha*C00z) * weight0;
            gout121 += (C00x) * (g88) * (2*alpha*C00z) * weight0;
            gout122 += (C00x) * (g76) * (2*alpha*g126) * weight0;
            gout123 += (g4) * (C00y) * (2*alpha*g136) * weight0;
            gout124 += (C00x) * (g66) * (2*alpha*g136) * weight0;
            gout125 += (C00x) * (C00y) * (2*alpha*g148) * weight0;
            gout126 += (g28) * (-1 + 2*alpha*g122) * weight0;
            gout127 += (g15) * (D00y) * (-1 + 2*alpha*g122) * weight0;
            gout128 += (g15) * (-D00z + 2*alpha*g129) * weight0;
            gout129 += (g4) * (g74) * (-1 + 2*alpha*g122) * weight0;
            gout130 += (C00x) * (g85) * (-1 + 2*alpha*g122) * weight0;
            gout131 += (C00x) * (g74) * (-D00z + 2*alpha*g129) * weight0;
            gout132 += (g4) * (-g134 + 2*alpha*g138) * weight0;
            gout133 += (C00x) * (D00y) * (-g134 + 2*alpha*g138) * weight0;
            gout134 += (C00x) * (-g145 + 2*alpha*g156) * weight0;
            gout135 += (g25) * (g62) * (2*alpha*C00z) * weight0;
            gout136 += (g13) * (g69) * (2*alpha*C00z) * weight0;
            gout137 += (g13) * (g62) * (2*alpha*g126) * weight0;
            gout138 += (D00x) * (g78) * (2*alpha*C00z) * weight0;
            gout139 += (g96) * (2*alpha*C00z) * weight0;
            gout140 += (g78) * (2*alpha*g126) * weight0;
            gout141 += (D00x) * (g62) * (2*alpha*g136) * weight0;
            gout142 += (g69) * (2*alpha*g136) * weight0;
            gout143 += (g62) * (2*alpha*g148) * weight0;
            gout144 += (g25) * (C00y) * (-1 + 2*alpha*g122) * weight0;
            gout145 += (g13) * (g66) * (-1 + 2*alpha*g122) * weight0;
            gout146 += (g13) * (C00y) * (-D00z + 2*alpha*g129) * weight0;
            gout147 += (D00x) * (g76) * (-1 + 2*alpha*g122) * weight0;
            gout148 += (g88) * (-1 + 2*alpha*g122) * weight0;
            gout149 += (g76) * (-D00z + 2*alpha*g129) * weight0;
            gout150 += (D00x) * (C00y) * (-g134 + 2*alpha*g138) * weight0;
            gout151 += (g66) * (-g134 + 2*alpha*g138) * weight0;
            gout152 += (C00y) * (-g145 + 2*alpha*g156) * weight0;
            gout153 += (g25) * (-2*C00z + 2*alpha*g124) * weight0;
            gout154 += (g13) * (D00y) * (-2*C00z + 2*alpha*g124) * weight0;
            gout155 += (g13) * (-2*g126 + 2*alpha*g133) * weight0;
            gout156 += (D00x) * (g74) * (-2*C00z + 2*alpha*g124) * weight0;
            gout157 += (g85) * (-2*C00z + 2*alpha*g124) * weight0;
            gout158 += (g74) * (-2*g126 + 2*alpha*g133) * weight0;
            gout159 += (D00x) * (-2*g136 + 2*alpha*g143) * weight0;
            gout160 += (D00y) * (-2*g136 + 2*alpha*g143) * weight0;
            gout161 += (-2*g148 + 2*alpha*g163) * weight0;
            gout162 += (-g7 + 2*beta*g61) * weight0;
            gout163 += (-g0 + 2*beta*g50) * (D00y) * weight0;
            gout164 += (-g0 + 2*beta*g50) * (D00z) * weight0;
            gout165 += (2*beta*g36) * (g74) * weight0;
            gout166 += (2*beta*g17) * (g85) * weight0;
            gout167 += (2*beta*g17) * (g74) * (D00z) * weight0;
            gout168 += (2*beta*g36) * (g134) * weight0;
            gout169 += (2*beta*g17) * (D00y) * (g134) * weight0;
            gout170 += (2*beta*g17) * (g145) * weight0;
            gout171 += (-g4 + 2*beta*g57) * (C00y) * weight0;
            gout172 += (-C00x + 2*beta*g47) * (g66) * weight0;
            gout173 += (-C00x + 2*beta*g47) * (C00y) * (D00z) * weight0;
            gout174 += (2*beta*g28) * (g76) * weight0;
            gout175 += (2*beta*g15) * (g88) * weight0;
            gout176 += (2*beta*g15) * (g76) * (D00z) * weight0;
            gout177 += (2*beta*g28) * (C00y) * (g134) * weight0;
            gout178 += (2*beta*g15) * (g66) * (g134) * weight0;
            gout179 += (2*beta*g15) * (C00y) * (g145) * weight0;
            gout180 += (-g4 + 2*beta*g57) * (C00z) * weight0;
            gout181 += (-C00x + 2*beta*g47) * (D00y) * (C00z) * weight0;
            gout182 += (-C00x + 2*beta*g47) * (g126) * weight0;
            gout183 += (2*beta*g28) * (g74) * (C00z) * weight0;
            gout184 += (2*beta*g15) * (g85) * (C00z) * weight0;
            gout185 += (2*beta*g15) * (g74) * (g126) * weight0;
            gout186 += (2*beta*g28) * (g136) * weight0;
            gout187 += (2*beta*g15) * (D00y) * (g136) * weight0;
            gout188 += (2*beta*g15) * (g148) * weight0;
            gout189 += (-D00x + 2*beta*g53) * (g62) * weight0;
            gout190 += (-1 + 2*beta*g44) * (g69) * weight0;
            gout191 += (-1 + 2*beta*g44) * (g62) * (D00z) * weight0;
            gout192 += (2*beta*g25) * (g78) * weight0;
            gout193 += (2*beta*g13) * (g96) * weight0;
            gout194 += (2*beta*g13) * (g78) * (D00z) * weight0;
            gout195 += (2*beta*g25) * (g62) * (g134) * weight0;
            gout196 += (2*beta*g13) * (g69) * (g134) * weight0;
            gout197 += (2*beta*g13) * (g62) * (g145) * weight0;
            gout198 += (-D00x + 2*beta*g53) * (C00y) * (C00z) * weight0;
            gout199 += (-1 + 2*beta*g44) * (g66) * (C00z) * weight0;
            gout200 += (-1 + 2*beta*g44) * (C00y) * (g126) * weight0;
            gout201 += (2*beta*g25) * (g76) * (C00z) * weight0;
            gout202 += (2*beta*g13) * (g88) * (C00z) * weight0;
            gout203 += (2*beta*g13) * (g76) * (g126) * weight0;
            gout204 += (2*beta*g25) * (C00y) * (g136) * weight0;
            gout205 += (2*beta*g13) * (g66) * (g136) * weight0;
            gout206 += (2*beta*g13) * (C00y) * (g148) * weight0;
            gout207 += (-D00x + 2*beta*g53) * (g122) * weight0;
            gout208 += (-1 + 2*beta*g44) * (D00y) * (g122) * weight0;
            gout209 += (-1 + 2*beta*g44) * (g129) * weight0;
            gout210 += (2*beta*g25) * (g74) * (g122) * weight0;
            gout211 += (2*beta*g13) * (g85) * (g122) * weight0;
            gout212 += (2*beta*g13) * (g74) * (g129) * weight0;
            gout213 += (2*beta*g25) * (g138) * weight0;
            gout214 += (2*beta*g13) * (D00y) * (g138) * weight0;
            gout215 += (2*beta*g13) * (g156) * weight0;
            gout216 += (g36) * (2*beta*g74) * weight0;
            gout217 += (g17) * (2*beta*g85) * weight0;
            gout218 += (g17) * (2*beta*g74) * (D00z) * weight0;
            gout219 += (g7) * (-1 + 2*beta*g104) * weight0;
            gout220 += (g0) * (-D00y + 2*beta*g113) * weight0;
            gout221 += (g0) * (-1 + 2*beta*g104) * (D00z) * weight0;
            gout222 += (g7) * (2*beta*g74) * (g134) * weight0;
            gout223 += (g0) * (2*beta*g85) * (g134) * weight0;
            gout224 += (g0) * (2*beta*g74) * (g145) * weight0;
            gout225 += (g28) * (2*beta*g76) * weight0;
            gout226 += (g15) * (2*beta*g88) * weight0;
            gout227 += (g15) * (2*beta*g76) * (D00z) * weight0;
            gout228 += (g4) * (-C00y + 2*beta*g107) * weight0;
            gout229 += (C00x) * (-g66 + 2*beta*g117) * weight0;
            gout230 += (C00x) * (-C00y + 2*beta*g107) * (D00z) * weight0;
            gout231 += (g4) * (2*beta*g76) * (g134) * weight0;
            gout232 += (C00x) * (2*beta*g88) * (g134) * weight0;
            gout233 += (C00x) * (2*beta*g76) * (g145) * weight0;
            gout234 += (g28) * (2*beta*g74) * (C00z) * weight0;
            gout235 += (g15) * (2*beta*g85) * (C00z) * weight0;
            gout236 += (g15) * (2*beta*g74) * (g126) * weight0;
            gout237 += (g4) * (-1 + 2*beta*g104) * (C00z) * weight0;
            gout238 += (C00x) * (-D00y + 2*beta*g113) * (C00z) * weight0;
            gout239 += (C00x) * (-1 + 2*beta*g104) * (g126) * weight0;
            gout240 += (g4) * (2*beta*g74) * (g136) * weight0;
            gout241 += (C00x) * (2*beta*g85) * (g136) * weight0;
            gout242 += (C00x) * (2*beta*g74) * (g148) * weight0;
            gout243 += (g25) * (2*beta*g78) * weight0;
            gout244 += (g13) * (2*beta*g96) * weight0;
            gout245 += (g13) * (2*beta*g78) * (D00z) * weight0;
            gout246 += (D00x) * (-g62 + 2*beta*g110) * weight0;
            gout247 += (-g69 + 2*beta*g121) * weight0;
            gout248 += (-g62 + 2*beta*g110) * (D00z) * weight0;
            gout249 += (D00x) * (2*beta*g78) * (g134) * weight0;
            gout250 += (2*beta*g96) * (g134) * weight0;
            gout251 += (2*beta*g78) * (g145) * weight0;
            gout252 += (g25) * (2*beta*g76) * (C00z) * weight0;
            gout253 += (g13) * (2*beta*g88) * (C00z) * weight0;
            gout254 += (g13) * (2*beta*g76) * (g126) * weight0;
            gout255 += (D00x) * (-C00y + 2*beta*g107) * (C00z) * weight0;
            gout256 += (-g66 + 2*beta*g117) * (C00z) * weight0;
            gout257 += (-C00y + 2*beta*g107) * (g126) * weight0;
            gout258 += (D00x) * (2*beta*g76) * (g136) * weight0;
            gout259 += (2*beta*g88) * (g136) * weight0;
            gout260 += (2*beta*g76) * (g148) * weight0;
            gout261 += (g25) * (2*beta*g74) * (g122) * weight0;
            gout262 += (g13) * (2*beta*g85) * (g122) * weight0;
            gout263 += (g13) * (2*beta*g74) * (g129) * weight0;
            gout264 += (D00x) * (-1 + 2*beta*g104) * (g122) * weight0;
            gout265 += (-D00y + 2*beta*g113) * (g122) * weight0;
            gout266 += (-1 + 2*beta*g104) * (g129) * weight0;
            gout267 += (D00x) * (2*beta*g74) * (g138) * weight0;
            gout268 += (2*beta*g85) * (g138) * weight0;
            gout269 += (2*beta*g74) * (g156) * weight0;
            gout270 += (g36) * (2*beta*g134) * weight0;
            gout271 += (g17) * (D00y) * (2*beta*g134) * weight0;
            gout272 += (g17) * (2*beta*g145) * weight0;
            gout273 += (g7) * (g74) * (2*beta*g134) * weight0;
            gout274 += (g0) * (g85) * (2*beta*g134) * weight0;
            gout275 += (g0) * (g74) * (2*beta*g145) * weight0;
            gout276 += (g7) * (-1 + 2*beta*g164) * weight0;
            gout277 += (g0) * (D00y) * (-1 + 2*beta*g164) * weight0;
            gout278 += (g0) * (-D00z + 2*beta*g173) * weight0;
            gout279 += (g28) * (C00y) * (2*beta*g134) * weight0;
            gout280 += (g15) * (g66) * (2*beta*g134) * weight0;
            gout281 += (g15) * (C00y) * (2*beta*g145) * weight0;
            gout282 += (g4) * (g76) * (2*beta*g134) * weight0;
            gout283 += (C00x) * (g88) * (2*beta*g134) * weight0;
            gout284 += (C00x) * (g76) * (2*beta*g145) * weight0;
            gout285 += (g4) * (C00y) * (-1 + 2*beta*g164) * weight0;
            gout286 += (C00x) * (g66) * (-1 + 2*beta*g164) * weight0;
            gout287 += (C00x) * (C00y) * (-D00z + 2*beta*g173) * weight0;
            gout288 += (g28) * (2*beta*g136) * weight0;
            gout289 += (g15) * (D00y) * (2*beta*g136) * weight0;
            gout290 += (g15) * (2*beta*g148) * weight0;
            gout291 += (g4) * (g74) * (2*beta*g136) * weight0;
            gout292 += (C00x) * (g85) * (2*beta*g136) * weight0;
            gout293 += (C00x) * (g74) * (2*beta*g148) * weight0;
            gout294 += (g4) * (-C00z + 2*beta*g167) * weight0;
            gout295 += (C00x) * (D00y) * (-C00z + 2*beta*g167) * weight0;
            gout296 += (C00x) * (-g126 + 2*beta*g177) * weight0;
            gout297 += (g25) * (g62) * (2*beta*g134) * weight0;
            gout298 += (g13) * (g69) * (2*beta*g134) * weight0;
            gout299 += (g13) * (g62) * (2*beta*g145) * weight0;
            gout300 += (D00x) * (g78) * (2*beta*g134) * weight0;
            gout301 += (g96) * (2*beta*g134) * weight0;
            gout302 += (g78) * (2*beta*g145) * weight0;
            gout303 += (D00x) * (g62) * (-1 + 2*beta*g164) * weight0;
            gout304 += (g69) * (-1 + 2*beta*g164) * weight0;
            gout305 += (g62) * (-D00z + 2*beta*g173) * weight0;
            gout306 += (g25) * (C00y) * (2*beta*g136) * weight0;
            gout307 += (g13) * (g66) * (2*beta*g136) * weight0;
            gout308 += (g13) * (C00y) * (2*beta*g148) * weight0;
            gout309 += (D00x) * (g76) * (2*beta*g136) * weight0;
            gout310 += (g88) * (2*beta*g136) * weight0;
            gout311 += (g76) * (2*beta*g148) * weight0;
            gout312 += (D00x) * (C00y) * (-C00z + 2*beta*g167) * weight0;
            gout313 += (g66) * (-C00z + 2*beta*g167) * weight0;
            gout314 += (C00y) * (-g126 + 2*beta*g177) * weight0;
            gout315 += (g25) * (2*beta*g138) * weight0;
            gout316 += (g13) * (D00y) * (2*beta*g138) * weight0;
            gout317 += (g13) * (2*beta*g156) * weight0;
            gout318 += (D00x) * (g74) * (2*beta*g138) * weight0;
            gout319 += (g85) * (2*beta*g138) * weight0;
            gout320 += (g74) * (2*beta*g156) * weight0;
            gout321 += (D00x) * (-g122 + 2*beta*g170) * weight0;
            gout322 += (D00y) * (-g122 + 2*beta*g170) * weight0;
            gout323 += (-g129 + 2*beta*g181) * weight0;
        }
    } }

    int *ao_loc = c_bpcache.ao_loc;
    int i0 = ao_loc[ish];
    int j0 = ao_loc[jsh];
    int k0 = ao_loc[ksh];
    int l0 = ao_loc[lsh];
    int n_dm = jk.n_dm;
    int nao = jk.nao;
    size_t nao2 = nao * nao;
    double* __restrict__ dm = jk.dm;
    double *vj = jk.vj;
    double *vk = jk.vk;
    double d_0, d_1, d_2, d_3, d_4, d_5, d_6, d_7, d_8, d_9, d_10, d_11, d_12, d_13, d_14, d_15, d_16, d_17;

    for (int i_dm = 0; i_dm < n_dm; ++i_dm) {
        if (vj != NULL) {
            d_0 = dm[(k0+0)+nao*(l0+0)];
            d_1 = dm[(k0+1)+nao*(l0+0)];
            d_2 = dm[(k0+2)+nao*(l0+0)];
            atomicAdd(vj+(i0+0)+nao*(j0+0), gout0*d_0+gout1*d_1+gout2*d_2);
            atomicAdd(vj+(i0+0)+nao*(j0+1), gout3*d_0+gout4*d_1+gout5*d_2);
            atomicAdd(vj+(i0+0)+nao*(j0+2), gout6*d_0+gout7*d_1+gout8*d_2);
            atomicAdd(vj+(i0+1)+nao*(j0+0), gout9*d_0+gout10*d_1+gout11*d_2);
            atomicAdd(vj+(i0+1)+nao*(j0+1), gout12*d_0+gout13*d_1+gout14*d_2);
            atomicAdd(vj+(i0+1)+nao*(j0+2), gout15*d_0+gout16*d_1+gout17*d_2);
            atomicAdd(vj+(i0+2)+nao*(j0+0), gout18*d_0+gout19*d_1+gout20*d_2);
            atomicAdd(vj+(i0+2)+nao*(j0+1), gout21*d_0+gout22*d_1+gout23*d_2);
            atomicAdd(vj+(i0+2)+nao*(j0+2), gout24*d_0+gout25*d_1+gout26*d_2);
            atomicAdd(vj+(i0+3)+nao*(j0+0), gout27*d_0+gout28*d_1+gout29*d_2);
            atomicAdd(vj+(i0+3)+nao*(j0+1), gout30*d_0+gout31*d_1+gout32*d_2);
            atomicAdd(vj+(i0+3)+nao*(j0+2), gout33*d_0+gout34*d_1+gout35*d_2);
            atomicAdd(vj+(i0+4)+nao*(j0+0), gout36*d_0+gout37*d_1+gout38*d_2);
            atomicAdd(vj+(i0+4)+nao*(j0+1), gout39*d_0+gout40*d_1+gout41*d_2);
            atomicAdd(vj+(i0+4)+nao*(j0+2), gout42*d_0+gout43*d_1+gout44*d_2);
            atomicAdd(vj+(i0+5)+nao*(j0+0), gout45*d_0+gout46*d_1+gout47*d_2);
            atomicAdd(vj+(i0+5)+nao*(j0+1), gout48*d_0+gout49*d_1+gout50*d_2);
            atomicAdd(vj+(i0+5)+nao*(j0+2), gout51*d_0+gout52*d_1+gout53*d_2);
            atomicAdd(vj+(i0+0)+nao*(j0+0)+nao2, gout54*d_0+gout55*d_1+gout56*d_2);
            atomicAdd(vj+(i0+0)+nao*(j0+1)+nao2, gout57*d_0+gout58*d_1+gout59*d_2);
            atomicAdd(vj+(i0+0)+nao*(j0+2)+nao2, gout60*d_0+gout61*d_1+gout62*d_2);
            atomicAdd(vj+(i0+1)+nao*(j0+0)+nao2, gout63*d_0+gout64*d_1+gout65*d_2);
            atomicAdd(vj+(i0+1)+nao*(j0+1)+nao2, gout66*d_0+gout67*d_1+gout68*d_2);
            atomicAdd(vj+(i0+1)+nao*(j0+2)+nao2, gout69*d_0+gout70*d_1+gout71*d_2);
            atomicAdd(vj+(i0+2)+nao*(j0+0)+nao2, gout72*d_0+gout73*d_1+gout74*d_2);
            atomicAdd(vj+(i0+2)+nao*(j0+1)+nao2, gout75*d_0+gout76*d_1+gout77*d_2);
            atomicAdd(vj+(i0+2)+nao*(j0+2)+nao2, gout78*d_0+gout79*d_1+gout80*d_2);
            atomicAdd(vj+(i0+3)+nao*(j0+0)+nao2, gout81*d_0+gout82*d_1+gout83*d_2);
            atomicAdd(vj+(i0+3)+nao*(j0+1)+nao2, gout84*d_0+gout85*d_1+gout86*d_2);
            atomicAdd(vj+(i0+3)+nao*(j0+2)+nao2, gout87*d_0+gout88*d_1+gout89*d_2);
            atomicAdd(vj+(i0+4)+nao*(j0+0)+nao2, gout90*d_0+gout91*d_1+gout92*d_2);
            atomicAdd(vj+(i0+4)+nao*(j0+1)+nao2, gout93*d_0+gout94*d_1+gout95*d_2);
            atomicAdd(vj+(i0+4)+nao*(j0+2)+nao2, gout96*d_0+gout97*d_1+gout98*d_2);
            atomicAdd(vj+(i0+5)+nao*(j0+0)+nao2, gout99*d_0+gout100*d_1+gout101*d_2);
            atomicAdd(vj+(i0+5)+nao*(j0+1)+nao2, gout102*d_0+gout103*d_1+gout104*d_2);
            atomicAdd(vj+(i0+5)+nao*(j0+2)+nao2, gout105*d_0+gout106*d_1+gout107*d_2);
            atomicAdd(vj+(i0+0)+nao*(j0+0)+2*nao2, gout108*d_0+gout109*d_1+gout110*d_2);
            atomicAdd(vj+(i0+0)+nao*(j0+1)+2*nao2, gout111*d_0+gout112*d_1+gout113*d_2);
            atomicAdd(vj+(i0+0)+nao*(j0+2)+2*nao2, gout114*d_0+gout115*d_1+gout116*d_2);
            atomicAdd(vj+(i0+1)+nao*(j0+0)+2*nao2, gout117*d_0+gout118*d_1+gout119*d_2);
            atomicAdd(vj+(i0+1)+nao*(j0+1)+2*nao2, gout120*d_0+gout121*d_1+gout122*d_2);
            atomicAdd(vj+(i0+1)+nao*(j0+2)+2*nao2, gout123*d_0+gout124*d_1+gout125*d_2);
            atomicAdd(vj+(i0+2)+nao*(j0+0)+2*nao2, gout126*d_0+gout127*d_1+gout128*d_2);
            atomicAdd(vj+(i0+2)+nao*(j0+1)+2*nao2, gout129*d_0+gout130*d_1+gout131*d_2);
            atomicAdd(vj+(i0+2)+nao*(j0+2)+2*nao2, gout132*d_0+gout133*d_1+gout134*d_2);
            atomicAdd(vj+(i0+3)+nao*(j0+0)+2*nao2, gout135*d_0+gout136*d_1+gout137*d_2);
            atomicAdd(vj+(i0+3)+nao*(j0+1)+2*nao2, gout138*d_0+gout139*d_1+gout140*d_2);
            atomicAdd(vj+(i0+3)+nao*(j0+2)+2*nao2, gout141*d_0+gout142*d_1+gout143*d_2);
            atomicAdd(vj+(i0+4)+nao*(j0+0)+2*nao2, gout144*d_0+gout145*d_1+gout146*d_2);
            atomicAdd(vj+(i0+4)+nao*(j0+1)+2*nao2, gout147*d_0+gout148*d_1+gout149*d_2);
            atomicAdd(vj+(i0+4)+nao*(j0+2)+2*nao2, gout150*d_0+gout151*d_1+gout152*d_2);
            atomicAdd(vj+(i0+5)+nao*(j0+0)+2*nao2, gout153*d_0+gout154*d_1+gout155*d_2);
            atomicAdd(vj+(i0+5)+nao*(j0+1)+2*nao2, gout156*d_0+gout157*d_1+gout158*d_2);
            atomicAdd(vj+(i0+5)+nao*(j0+2)+2*nao2, gout159*d_0+gout160*d_1+gout161*d_2);
            atomicAdd(vj+nao*(i0+0)+(j0+0), gout162*d_0+gout163*d_1+gout164*d_2);
            atomicAdd(vj+nao*(i0+0)+(j0+1), gout165*d_0+gout166*d_1+gout167*d_2);
            atomicAdd(vj+nao*(i0+0)+(j0+2), gout168*d_0+gout169*d_1+gout170*d_2);
            atomicAdd(vj+nao*(i0+1)+(j0+0), gout171*d_0+gout172*d_1+gout173*d_2);
            atomicAdd(vj+nao*(i0+1)+(j0+1), gout174*d_0+gout175*d_1+gout176*d_2);
            atomicAdd(vj+nao*(i0+1)+(j0+2), gout177*d_0+gout178*d_1+gout179*d_2);
            atomicAdd(vj+nao*(i0+2)+(j0+0), gout180*d_0+gout181*d_1+gout182*d_2);
            atomicAdd(vj+nao*(i0+2)+(j0+1), gout183*d_0+gout184*d_1+gout185*d_2);
            atomicAdd(vj+nao*(i0+2)+(j0+2), gout186*d_0+gout187*d_1+gout188*d_2);
            atomicAdd(vj+nao*(i0+3)+(j0+0), gout189*d_0+gout190*d_1+gout191*d_2);
            atomicAdd(vj+nao*(i0+3)+(j0+1), gout192*d_0+gout193*d_1+gout194*d_2);
            atomicAdd(vj+nao*(i0+3)+(j0+2), gout195*d_0+gout196*d_1+gout197*d_2);
            atomicAdd(vj+nao*(i0+4)+(j0+0), gout198*d_0+gout199*d_1+gout200*d_2);
            atomicAdd(vj+nao*(i0+4)+(j0+1), gout201*d_0+gout202*d_1+gout203*d_2);
            atomicAdd(vj+nao*(i0+4)+(j0+2), gout204*d_0+gout205*d_1+gout206*d_2);
            atomicAdd(vj+nao*(i0+5)+(j0+0), gout207*d_0+gout208*d_1+gout209*d_2);
            atomicAdd(vj+nao*(i0+5)+(j0+1), gout210*d_0+gout211*d_1+gout212*d_2);
            atomicAdd(vj+nao*(i0+5)+(j0+2), gout213*d_0+gout214*d_1+gout215*d_2);
            atomicAdd(vj+nao*(i0+0)+(j0+0)+nao2, gout216*d_0+gout217*d_1+gout218*d_2);
            atomicAdd(vj+nao*(i0+0)+(j0+1)+nao2, gout219*d_0+gout220*d_1+gout221*d_2);
            atomicAdd(vj+nao*(i0+0)+(j0+2)+nao2, gout222*d_0+gout223*d_1+gout224*d_2);
            atomicAdd(vj+nao*(i0+1)+(j0+0)+nao2, gout225*d_0+gout226*d_1+gout227*d_2);
            atomicAdd(vj+nao*(i0+1)+(j0+1)+nao2, gout228*d_0+gout229*d_1+gout230*d_2);
            atomicAdd(vj+nao*(i0+1)+(j0+2)+nao2, gout231*d_0+gout232*d_1+gout233*d_2);
            atomicAdd(vj+nao*(i0+2)+(j0+0)+nao2, gout234*d_0+gout235*d_1+gout236*d_2);
            atomicAdd(vj+nao*(i0+2)+(j0+1)+nao2, gout237*d_0+gout238*d_1+gout239*d_2);
            atomicAdd(vj+nao*(i0+2)+(j0+2)+nao2, gout240*d_0+gout241*d_1+gout242*d_2);
            atomicAdd(vj+nao*(i0+3)+(j0+0)+nao2, gout243*d_0+gout244*d_1+gout245*d_2);
            atomicAdd(vj+nao*(i0+3)+(j0+1)+nao2, gout246*d_0+gout247*d_1+gout248*d_2);
            atomicAdd(vj+nao*(i0+3)+(j0+2)+nao2, gout249*d_0+gout250*d_1+gout251*d_2);
            atomicAdd(vj+nao*(i0+4)+(j0+0)+nao2, gout252*d_0+gout253*d_1+gout254*d_2);
            atomicAdd(vj+nao*(i0+4)+(j0+1)+nao2, gout255*d_0+gout256*d_1+gout257*d_2);
            atomicAdd(vj+nao*(i0+4)+(j0+2)+nao2, gout258*d_0+gout259*d_1+gout260*d_2);
            atomicAdd(vj+nao*(i0+5)+(j0+0)+nao2, gout261*d_0+gout262*d_1+gout263*d_2);
            atomicAdd(vj+nao*(i0+5)+(j0+1)+nao2, gout264*d_0+gout265*d_1+gout266*d_2);
            atomicAdd(vj+nao*(i0+5)+(j0+2)+nao2, gout267*d_0+gout268*d_1+gout269*d_2);
            atomicAdd(vj+nao*(i0+0)+(j0+0)+2*nao2, gout270*d_0+gout271*d_1+gout272*d_2);
            atomicAdd(vj+nao*(i0+0)+(j0+1)+2*nao2, gout273*d_0+gout274*d_1+gout275*d_2);
            atomicAdd(vj+nao*(i0+0)+(j0+2)+2*nao2, gout276*d_0+gout277*d_1+gout278*d_2);
            atomicAdd(vj+nao*(i0+1)+(j0+0)+2*nao2, gout279*d_0+gout280*d_1+gout281*d_2);
            atomicAdd(vj+nao*(i0+1)+(j0+1)+2*nao2, gout282*d_0+gout283*d_1+gout284*d_2);
            atomicAdd(vj+nao*(i0+1)+(j0+2)+2*nao2, gout285*d_0+gout286*d_1+gout287*d_2);
            atomicAdd(vj+nao*(i0+2)+(j0+0)+2*nao2, gout288*d_0+gout289*d_1+gout290*d_2);
            atomicAdd(vj+nao*(i0+2)+(j0+1)+2*nao2, gout291*d_0+gout292*d_1+gout293*d_2);
            atomicAdd(vj+nao*(i0+2)+(j0+2)+2*nao2, gout294*d_0+gout295*d_1+gout296*d_2);
            atomicAdd(vj+nao*(i0+3)+(j0+0)+2*nao2, gout297*d_0+gout298*d_1+gout299*d_2);
            atomicAdd(vj+nao*(i0+3)+(j0+1)+2*nao2, gout300*d_0+gout301*d_1+gout302*d_2);
            atomicAdd(vj+nao*(i0+3)+(j0+2)+2*nao2, gout303*d_0+gout304*d_1+gout305*d_2);
            atomicAdd(vj+nao*(i0+4)+(j0+0)+2*nao2, gout306*d_0+gout307*d_1+gout308*d_2);
            atomicAdd(vj+nao*(i0+4)+(j0+1)+2*nao2, gout309*d_0+gout310*d_1+gout311*d_2);
            atomicAdd(vj+nao*(i0+4)+(j0+2)+2*nao2, gout312*d_0+gout313*d_1+gout314*d_2);
            atomicAdd(vj+nao*(i0+5)+(j0+0)+2*nao2, gout315*d_0+gout316*d_1+gout317*d_2);
            atomicAdd(vj+nao*(i0+5)+(j0+1)+2*nao2, gout318*d_0+gout319*d_1+gout320*d_2);
            atomicAdd(vj+nao*(i0+5)+(j0+2)+2*nao2, gout321*d_0+gout322*d_1+gout323*d_2);
            vj += 3*nao2;
        }
        if (vk != NULL) {
            // ijkl, jk -> il
            d_0 = dm[(j0+0)+nao*(k0+0)];
            d_1 = dm[(j0+0)+nao*(k0+1)];
            d_2 = dm[(j0+0)+nao*(k0+2)];
            d_3 = dm[(j0+1)+nao*(k0+0)];
            d_4 = dm[(j0+1)+nao*(k0+1)];
            d_5 = dm[(j0+1)+nao*(k0+2)];
            d_6 = dm[(j0+2)+nao*(k0+0)];
            d_7 = dm[(j0+2)+nao*(k0+1)];
            d_8 = dm[(j0+2)+nao*(k0+2)];
            atomicAdd(vk+(i0+0)+nao*(l0+0), gout0*d_0+gout1*d_1+gout2*d_2+gout3*d_3+gout4*d_4+gout5*d_5+gout6*d_6+gout7*d_7+gout8*d_8);
            atomicAdd(vk+(i0+1)+nao*(l0+0), gout9*d_0+gout10*d_1+gout11*d_2+gout12*d_3+gout13*d_4+gout14*d_5+gout15*d_6+gout16*d_7+gout17*d_8);
            atomicAdd(vk+(i0+2)+nao*(l0+0), gout18*d_0+gout19*d_1+gout20*d_2+gout21*d_3+gout22*d_4+gout23*d_5+gout24*d_6+gout25*d_7+gout26*d_8);
            atomicAdd(vk+(i0+3)+nao*(l0+0), gout27*d_0+gout28*d_1+gout29*d_2+gout30*d_3+gout31*d_4+gout32*d_5+gout33*d_6+gout34*d_7+gout35*d_8);
            atomicAdd(vk+(i0+4)+nao*(l0+0), gout36*d_0+gout37*d_1+gout38*d_2+gout39*d_3+gout40*d_4+gout41*d_5+gout42*d_6+gout43*d_7+gout44*d_8);
            atomicAdd(vk+(i0+5)+nao*(l0+0), gout45*d_0+gout46*d_1+gout47*d_2+gout48*d_3+gout49*d_4+gout50*d_5+gout51*d_6+gout52*d_7+gout53*d_8);
            atomicAdd(vk+(i0+0)+nao*(l0+0)+nao2, gout54*d_0+gout55*d_1+gout56*d_2+gout57*d_3+gout58*d_4+gout59*d_5+gout60*d_6+gout61*d_7+gout62*d_8);
            atomicAdd(vk+(i0+1)+nao*(l0+0)+nao2, gout63*d_0+gout64*d_1+gout65*d_2+gout66*d_3+gout67*d_4+gout68*d_5+gout69*d_6+gout70*d_7+gout71*d_8);
            atomicAdd(vk+(i0+2)+nao*(l0+0)+nao2, gout72*d_0+gout73*d_1+gout74*d_2+gout75*d_3+gout76*d_4+gout77*d_5+gout78*d_6+gout79*d_7+gout80*d_8);
            atomicAdd(vk+(i0+3)+nao*(l0+0)+nao2, gout81*d_0+gout82*d_1+gout83*d_2+gout84*d_3+gout85*d_4+gout86*d_5+gout87*d_6+gout88*d_7+gout89*d_8);
            atomicAdd(vk+(i0+4)+nao*(l0+0)+nao2, gout90*d_0+gout91*d_1+gout92*d_2+gout93*d_3+gout94*d_4+gout95*d_5+gout96*d_6+gout97*d_7+gout98*d_8);
            atomicAdd(vk+(i0+5)+nao*(l0+0)+nao2, gout99*d_0+gout100*d_1+gout101*d_2+gout102*d_3+gout103*d_4+gout104*d_5+gout105*d_6+gout106*d_7+gout107*d_8);
            atomicAdd(vk+(i0+0)+nao*(l0+0)+2*nao2, gout108*d_0+gout109*d_1+gout110*d_2+gout111*d_3+gout112*d_4+gout113*d_5+gout114*d_6+gout115*d_7+gout116*d_8);
            atomicAdd(vk+(i0+1)+nao*(l0+0)+2*nao2, gout117*d_0+gout118*d_1+gout119*d_2+gout120*d_3+gout121*d_4+gout122*d_5+gout123*d_6+gout124*d_7+gout125*d_8);
            atomicAdd(vk+(i0+2)+nao*(l0+0)+2*nao2, gout126*d_0+gout127*d_1+gout128*d_2+gout129*d_3+gout130*d_4+gout131*d_5+gout132*d_6+gout133*d_7+gout134*d_8);
            atomicAdd(vk+(i0+3)+nao*(l0+0)+2*nao2, gout135*d_0+gout136*d_1+gout137*d_2+gout138*d_3+gout139*d_4+gout140*d_5+gout141*d_6+gout142*d_7+gout143*d_8);
            atomicAdd(vk+(i0+4)+nao*(l0+0)+2*nao2, gout144*d_0+gout145*d_1+gout146*d_2+gout147*d_3+gout148*d_4+gout149*d_5+gout150*d_6+gout151*d_7+gout152*d_8);
            atomicAdd(vk+(i0+5)+nao*(l0+0)+2*nao2, gout153*d_0+gout154*d_1+gout155*d_2+gout156*d_3+gout157*d_4+gout158*d_5+gout159*d_6+gout160*d_7+gout161*d_8);
            // ijkl, jl -> ik
            d_0 = dm[(j0+0)+nao*(l0+0)];
            d_1 = dm[(j0+1)+nao*(l0+0)];
            d_2 = dm[(j0+2)+nao*(l0+0)];
            atomicAdd(vk+(i0+0)+nao*(k0+0), gout0*d_0+gout3*d_1+gout6*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+1), gout1*d_0+gout4*d_1+gout7*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+2), gout2*d_0+gout5*d_1+gout8*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+0), gout9*d_0+gout12*d_1+gout15*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+1), gout10*d_0+gout13*d_1+gout16*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+2), gout11*d_0+gout14*d_1+gout17*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+0), gout18*d_0+gout21*d_1+gout24*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+1), gout19*d_0+gout22*d_1+gout25*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+2), gout20*d_0+gout23*d_1+gout26*d_2);
            atomicAdd(vk+(i0+3)+nao*(k0+0), gout27*d_0+gout30*d_1+gout33*d_2);
            atomicAdd(vk+(i0+3)+nao*(k0+1), gout28*d_0+gout31*d_1+gout34*d_2);
            atomicAdd(vk+(i0+3)+nao*(k0+2), gout29*d_0+gout32*d_1+gout35*d_2);
            atomicAdd(vk+(i0+4)+nao*(k0+0), gout36*d_0+gout39*d_1+gout42*d_2);
            atomicAdd(vk+(i0+4)+nao*(k0+1), gout37*d_0+gout40*d_1+gout43*d_2);
            atomicAdd(vk+(i0+4)+nao*(k0+2), gout38*d_0+gout41*d_1+gout44*d_2);
            atomicAdd(vk+(i0+5)+nao*(k0+0), gout45*d_0+gout48*d_1+gout51*d_2);
            atomicAdd(vk+(i0+5)+nao*(k0+1), gout46*d_0+gout49*d_1+gout52*d_2);
            atomicAdd(vk+(i0+5)+nao*(k0+2), gout47*d_0+gout50*d_1+gout53*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+0)+nao2, gout54*d_0+gout57*d_1+gout60*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+1)+nao2, gout55*d_0+gout58*d_1+gout61*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+2)+nao2, gout56*d_0+gout59*d_1+gout62*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+0)+nao2, gout63*d_0+gout66*d_1+gout69*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+1)+nao2, gout64*d_0+gout67*d_1+gout70*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+2)+nao2, gout65*d_0+gout68*d_1+gout71*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+0)+nao2, gout72*d_0+gout75*d_1+gout78*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+1)+nao2, gout73*d_0+gout76*d_1+gout79*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+2)+nao2, gout74*d_0+gout77*d_1+gout80*d_2);
            atomicAdd(vk+(i0+3)+nao*(k0+0)+nao2, gout81*d_0+gout84*d_1+gout87*d_2);
            atomicAdd(vk+(i0+3)+nao*(k0+1)+nao2, gout82*d_0+gout85*d_1+gout88*d_2);
            atomicAdd(vk+(i0+3)+nao*(k0+2)+nao2, gout83*d_0+gout86*d_1+gout89*d_2);
            atomicAdd(vk+(i0+4)+nao*(k0+0)+nao2, gout90*d_0+gout93*d_1+gout96*d_2);
            atomicAdd(vk+(i0+4)+nao*(k0+1)+nao2, gout91*d_0+gout94*d_1+gout97*d_2);
            atomicAdd(vk+(i0+4)+nao*(k0+2)+nao2, gout92*d_0+gout95*d_1+gout98*d_2);
            atomicAdd(vk+(i0+5)+nao*(k0+0)+nao2, gout99*d_0+gout102*d_1+gout105*d_2);
            atomicAdd(vk+(i0+5)+nao*(k0+1)+nao2, gout100*d_0+gout103*d_1+gout106*d_2);
            atomicAdd(vk+(i0+5)+nao*(k0+2)+nao2, gout101*d_0+gout104*d_1+gout107*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+0)+2*nao2, gout108*d_0+gout111*d_1+gout114*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+1)+2*nao2, gout109*d_0+gout112*d_1+gout115*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+2)+2*nao2, gout110*d_0+gout113*d_1+gout116*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+0)+2*nao2, gout117*d_0+gout120*d_1+gout123*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+1)+2*nao2, gout118*d_0+gout121*d_1+gout124*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+2)+2*nao2, gout119*d_0+gout122*d_1+gout125*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+0)+2*nao2, gout126*d_0+gout129*d_1+gout132*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+1)+2*nao2, gout127*d_0+gout130*d_1+gout133*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+2)+2*nao2, gout128*d_0+gout131*d_1+gout134*d_2);
            atomicAdd(vk+(i0+3)+nao*(k0+0)+2*nao2, gout135*d_0+gout138*d_1+gout141*d_2);
            atomicAdd(vk+(i0+3)+nao*(k0+1)+2*nao2, gout136*d_0+gout139*d_1+gout142*d_2);
            atomicAdd(vk+(i0+3)+nao*(k0+2)+2*nao2, gout137*d_0+gout140*d_1+gout143*d_2);
            atomicAdd(vk+(i0+4)+nao*(k0+0)+2*nao2, gout144*d_0+gout147*d_1+gout150*d_2);
            atomicAdd(vk+(i0+4)+nao*(k0+1)+2*nao2, gout145*d_0+gout148*d_1+gout151*d_2);
            atomicAdd(vk+(i0+4)+nao*(k0+2)+2*nao2, gout146*d_0+gout149*d_1+gout152*d_2);
            atomicAdd(vk+(i0+5)+nao*(k0+0)+2*nao2, gout153*d_0+gout156*d_1+gout159*d_2);
            atomicAdd(vk+(i0+5)+nao*(k0+1)+2*nao2, gout154*d_0+gout157*d_1+gout160*d_2);
            atomicAdd(vk+(i0+5)+nao*(k0+2)+2*nao2, gout155*d_0+gout158*d_1+gout161*d_2);
            // ijkl, ik -> jl
            d_0 = dm[(i0+0)+nao*(k0+0)];
            d_1 = dm[(i0+0)+nao*(k0+1)];
            d_2 = dm[(i0+0)+nao*(k0+2)];
            d_3 = dm[(i0+1)+nao*(k0+0)];
            d_4 = dm[(i0+1)+nao*(k0+1)];
            d_5 = dm[(i0+1)+nao*(k0+2)];
            d_6 = dm[(i0+2)+nao*(k0+0)];
            d_7 = dm[(i0+2)+nao*(k0+1)];
            d_8 = dm[(i0+2)+nao*(k0+2)];
            d_9 = dm[(i0+3)+nao*(k0+0)];
            d_10 = dm[(i0+3)+nao*(k0+1)];
            d_11 = dm[(i0+3)+nao*(k0+2)];
            d_12 = dm[(i0+4)+nao*(k0+0)];
            d_13 = dm[(i0+4)+nao*(k0+1)];
            d_14 = dm[(i0+4)+nao*(k0+2)];
            d_15 = dm[(i0+5)+nao*(k0+0)];
            d_16 = dm[(i0+5)+nao*(k0+1)];
            d_17 = dm[(i0+5)+nao*(k0+2)];
            atomicAdd(vk+(j0+0)+nao*(l0+0), gout162*d_0+gout163*d_1+gout164*d_2+gout171*d_3+gout172*d_4+gout173*d_5+gout180*d_6+gout181*d_7+gout182*d_8+gout189*d_9+gout190*d_10+gout191*d_11+gout198*d_12+gout199*d_13+gout200*d_14+gout207*d_15+gout208*d_16+gout209*d_17);
            atomicAdd(vk+(j0+1)+nao*(l0+0), gout165*d_0+gout166*d_1+gout167*d_2+gout174*d_3+gout175*d_4+gout176*d_5+gout183*d_6+gout184*d_7+gout185*d_8+gout192*d_9+gout193*d_10+gout194*d_11+gout201*d_12+gout202*d_13+gout203*d_14+gout210*d_15+gout211*d_16+gout212*d_17);
            atomicAdd(vk+(j0+2)+nao*(l0+0), gout168*d_0+gout169*d_1+gout170*d_2+gout177*d_3+gout178*d_4+gout179*d_5+gout186*d_6+gout187*d_7+gout188*d_8+gout195*d_9+gout196*d_10+gout197*d_11+gout204*d_12+gout205*d_13+gout206*d_14+gout213*d_15+gout214*d_16+gout215*d_17);
            atomicAdd(vk+(j0+0)+nao*(l0+0)+nao2, gout216*d_0+gout217*d_1+gout218*d_2+gout225*d_3+gout226*d_4+gout227*d_5+gout234*d_6+gout235*d_7+gout236*d_8+gout243*d_9+gout244*d_10+gout245*d_11+gout252*d_12+gout253*d_13+gout254*d_14+gout261*d_15+gout262*d_16+gout263*d_17);
            atomicAdd(vk+(j0+1)+nao*(l0+0)+nao2, gout219*d_0+gout220*d_1+gout221*d_2+gout228*d_3+gout229*d_4+gout230*d_5+gout237*d_6+gout238*d_7+gout239*d_8+gout246*d_9+gout247*d_10+gout248*d_11+gout255*d_12+gout256*d_13+gout257*d_14+gout264*d_15+gout265*d_16+gout266*d_17);
            atomicAdd(vk+(j0+2)+nao*(l0+0)+nao2, gout222*d_0+gout223*d_1+gout224*d_2+gout231*d_3+gout232*d_4+gout233*d_5+gout240*d_6+gout241*d_7+gout242*d_8+gout249*d_9+gout250*d_10+gout251*d_11+gout258*d_12+gout259*d_13+gout260*d_14+gout267*d_15+gout268*d_16+gout269*d_17);
            atomicAdd(vk+(j0+0)+nao*(l0+0)+2*nao2, gout270*d_0+gout271*d_1+gout272*d_2+gout279*d_3+gout280*d_4+gout281*d_5+gout288*d_6+gout289*d_7+gout290*d_8+gout297*d_9+gout298*d_10+gout299*d_11+gout306*d_12+gout307*d_13+gout308*d_14+gout315*d_15+gout316*d_16+gout317*d_17);
            atomicAdd(vk+(j0+1)+nao*(l0+0)+2*nao2, gout273*d_0+gout274*d_1+gout275*d_2+gout282*d_3+gout283*d_4+gout284*d_5+gout291*d_6+gout292*d_7+gout293*d_8+gout300*d_9+gout301*d_10+gout302*d_11+gout309*d_12+gout310*d_13+gout311*d_14+gout318*d_15+gout319*d_16+gout320*d_17);
            atomicAdd(vk+(j0+2)+nao*(l0+0)+2*nao2, gout276*d_0+gout277*d_1+gout278*d_2+gout285*d_3+gout286*d_4+gout287*d_5+gout294*d_6+gout295*d_7+gout296*d_8+gout303*d_9+gout304*d_10+gout305*d_11+gout312*d_12+gout313*d_13+gout314*d_14+gout321*d_15+gout322*d_16+gout323*d_17);
            // ijkl, il -> jk
            d_0 = dm[(i0+0)+nao*(l0+0)];
            d_1 = dm[(i0+1)+nao*(l0+0)];
            d_2 = dm[(i0+2)+nao*(l0+0)];
            d_3 = dm[(i0+3)+nao*(l0+0)];
            d_4 = dm[(i0+4)+nao*(l0+0)];
            d_5 = dm[(i0+5)+nao*(l0+0)];
            atomicAdd(vk+(j0+0)+nao*(k0+0), gout162*d_0+gout171*d_1+gout180*d_2+gout189*d_3+gout198*d_4+gout207*d_5);
            atomicAdd(vk+(j0+0)+nao*(k0+1), gout163*d_0+gout172*d_1+gout181*d_2+gout190*d_3+gout199*d_4+gout208*d_5);
            atomicAdd(vk+(j0+0)+nao*(k0+2), gout164*d_0+gout173*d_1+gout182*d_2+gout191*d_3+gout200*d_4+gout209*d_5);
            atomicAdd(vk+(j0+1)+nao*(k0+0), gout165*d_0+gout174*d_1+gout183*d_2+gout192*d_3+gout201*d_4+gout210*d_5);
            atomicAdd(vk+(j0+1)+nao*(k0+1), gout166*d_0+gout175*d_1+gout184*d_2+gout193*d_3+gout202*d_4+gout211*d_5);
            atomicAdd(vk+(j0+1)+nao*(k0+2), gout167*d_0+gout176*d_1+gout185*d_2+gout194*d_3+gout203*d_4+gout212*d_5);
            atomicAdd(vk+(j0+2)+nao*(k0+0), gout168*d_0+gout177*d_1+gout186*d_2+gout195*d_3+gout204*d_4+gout213*d_5);
            atomicAdd(vk+(j0+2)+nao*(k0+1), gout169*d_0+gout178*d_1+gout187*d_2+gout196*d_3+gout205*d_4+gout214*d_5);
            atomicAdd(vk+(j0+2)+nao*(k0+2), gout170*d_0+gout179*d_1+gout188*d_2+gout197*d_3+gout206*d_4+gout215*d_5);
            atomicAdd(vk+(j0+0)+nao*(k0+0)+nao2, gout216*d_0+gout225*d_1+gout234*d_2+gout243*d_3+gout252*d_4+gout261*d_5);
            atomicAdd(vk+(j0+0)+nao*(k0+1)+nao2, gout217*d_0+gout226*d_1+gout235*d_2+gout244*d_3+gout253*d_4+gout262*d_5);
            atomicAdd(vk+(j0+0)+nao*(k0+2)+nao2, gout218*d_0+gout227*d_1+gout236*d_2+gout245*d_3+gout254*d_4+gout263*d_5);
            atomicAdd(vk+(j0+1)+nao*(k0+0)+nao2, gout219*d_0+gout228*d_1+gout237*d_2+gout246*d_3+gout255*d_4+gout264*d_5);
            atomicAdd(vk+(j0+1)+nao*(k0+1)+nao2, gout220*d_0+gout229*d_1+gout238*d_2+gout247*d_3+gout256*d_4+gout265*d_5);
            atomicAdd(vk+(j0+1)+nao*(k0+2)+nao2, gout221*d_0+gout230*d_1+gout239*d_2+gout248*d_3+gout257*d_4+gout266*d_5);
            atomicAdd(vk+(j0+2)+nao*(k0+0)+nao2, gout222*d_0+gout231*d_1+gout240*d_2+gout249*d_3+gout258*d_4+gout267*d_5);
            atomicAdd(vk+(j0+2)+nao*(k0+1)+nao2, gout223*d_0+gout232*d_1+gout241*d_2+gout250*d_3+gout259*d_4+gout268*d_5);
            atomicAdd(vk+(j0+2)+nao*(k0+2)+nao2, gout224*d_0+gout233*d_1+gout242*d_2+gout251*d_3+gout260*d_4+gout269*d_5);
            atomicAdd(vk+(j0+0)+nao*(k0+0)+2*nao2, gout270*d_0+gout279*d_1+gout288*d_2+gout297*d_3+gout306*d_4+gout315*d_5);
            atomicAdd(vk+(j0+0)+nao*(k0+1)+2*nao2, gout271*d_0+gout280*d_1+gout289*d_2+gout298*d_3+gout307*d_4+gout316*d_5);
            atomicAdd(vk+(j0+0)+nao*(k0+2)+2*nao2, gout272*d_0+gout281*d_1+gout290*d_2+gout299*d_3+gout308*d_4+gout317*d_5);
            atomicAdd(vk+(j0+1)+nao*(k0+0)+2*nao2, gout273*d_0+gout282*d_1+gout291*d_2+gout300*d_3+gout309*d_4+gout318*d_5);
            atomicAdd(vk+(j0+1)+nao*(k0+1)+2*nao2, gout274*d_0+gout283*d_1+gout292*d_2+gout301*d_3+gout310*d_4+gout319*d_5);
            atomicAdd(vk+(j0+1)+nao*(k0+2)+2*nao2, gout275*d_0+gout284*d_1+gout293*d_2+gout302*d_3+gout311*d_4+gout320*d_5);
            atomicAdd(vk+(j0+2)+nao*(k0+0)+2*nao2, gout276*d_0+gout285*d_1+gout294*d_2+gout303*d_3+gout312*d_4+gout321*d_5);
            atomicAdd(vk+(j0+2)+nao*(k0+1)+2*nao2, gout277*d_0+gout286*d_1+gout295*d_2+gout304*d_3+gout313*d_4+gout322*d_5);
            atomicAdd(vk+(j0+2)+nao*(k0+2)+2*nao2, gout278*d_0+gout287*d_1+gout296*d_2+gout305*d_3+gout314*d_4+gout323*d_5);
            vk += 3*nao2;
        }
        dm += nao2;
    }
}

__global__
static void GINTint2e_ip1_jk_kernel_2200(GINTEnvVars envs, JKMatrix jk,
                                    BasisProdOffsets offsets)
{
    int ntasks_ij = offsets.ntasks_ij;
    int ntasks_kl = offsets.ntasks_kl;
    int task_ij = blockIdx.x * blockDim.x + threadIdx.x;
    int task_kl = blockIdx.y * blockDim.y + threadIdx.y;
    if (task_ij >= ntasks_ij || task_kl >= ntasks_kl) {
        return;
    }
    int bas_ij = offsets.bas_ij + task_ij;
    int bas_kl = offsets.bas_kl + task_kl;
    double norm = envs.fac;
    double omega = envs.omega;
    int *bas_pair2bra = c_bpcache.bas_pair2bra;
    int *bas_pair2ket = c_bpcache.bas_pair2ket;
    int ish = bas_pair2bra[bas_ij];
    int jsh = bas_pair2ket[bas_ij];
    int ksh = bas_pair2bra[bas_kl];
    int lsh = bas_pair2ket[bas_kl];
    int nprim_ij = envs.nprim_ij;
    int nprim_kl = envs.nprim_kl;
    int prim_ij = offsets.primitive_ij + task_ij * nprim_ij;
    int prim_kl = offsets.primitive_kl + task_kl * nprim_kl;

    double* __restrict__ a12 = c_bpcache.a12;
    double* __restrict__ e12 = c_bpcache.e12;
    double* __restrict__ x12 = c_bpcache.x12;
    double* __restrict__ y12 = c_bpcache.y12;
    double* __restrict__ z12 = c_bpcache.z12;
    double * __restrict__ i_exponent = c_bpcache.a1;
    double * __restrict__ j_exponent = c_bpcache.a2;

    int ij, kl;
    int prim_ij0, prim_ij1, prim_kl0, prim_kl1;
    int nbas = c_bpcache.nbas;
    double* __restrict__ bas_x = c_bpcache.bas_coords;
    double* __restrict__ bas_y = bas_x + nbas;
    double* __restrict__ bas_z = bas_y + nbas;

    double gout0 = 0;
    double gout1 = 0;
    double gout2 = 0;
    double gout3 = 0;
    double gout4 = 0;
    double gout5 = 0;
    double gout6 = 0;
    double gout7 = 0;
    double gout8 = 0;
    double gout9 = 0;
    double gout10 = 0;
    double gout11 = 0;
    double gout12 = 0;
    double gout13 = 0;
    double gout14 = 0;
    double gout15 = 0;
    double gout16 = 0;
    double gout17 = 0;
    double gout18 = 0;
    double gout19 = 0;
    double gout20 = 0;
    double gout21 = 0;
    double gout22 = 0;
    double gout23 = 0;
    double gout24 = 0;
    double gout25 = 0;
    double gout26 = 0;
    double gout27 = 0;
    double gout28 = 0;
    double gout29 = 0;
    double gout30 = 0;
    double gout31 = 0;
    double gout32 = 0;
    double gout33 = 0;
    double gout34 = 0;
    double gout35 = 0;
    double gout36 = 0;
    double gout37 = 0;
    double gout38 = 0;
    double gout39 = 0;
    double gout40 = 0;
    double gout41 = 0;
    double gout42 = 0;
    double gout43 = 0;
    double gout44 = 0;
    double gout45 = 0;
    double gout46 = 0;
    double gout47 = 0;
    double gout48 = 0;
    double gout49 = 0;
    double gout50 = 0;
    double gout51 = 0;
    double gout52 = 0;
    double gout53 = 0;
    double gout54 = 0;
    double gout55 = 0;
    double gout56 = 0;
    double gout57 = 0;
    double gout58 = 0;
    double gout59 = 0;
    double gout60 = 0;
    double gout61 = 0;
    double gout62 = 0;
    double gout63 = 0;
    double gout64 = 0;
    double gout65 = 0;
    double gout66 = 0;
    double gout67 = 0;
    double gout68 = 0;
    double gout69 = 0;
    double gout70 = 0;
    double gout71 = 0;
    double gout72 = 0;
    double gout73 = 0;
    double gout74 = 0;
    double gout75 = 0;
    double gout76 = 0;
    double gout77 = 0;
    double gout78 = 0;
    double gout79 = 0;
    double gout80 = 0;
    double gout81 = 0;
    double gout82 = 0;
    double gout83 = 0;
    double gout84 = 0;
    double gout85 = 0;
    double gout86 = 0;
    double gout87 = 0;
    double gout88 = 0;
    double gout89 = 0;
    double gout90 = 0;
    double gout91 = 0;
    double gout92 = 0;
    double gout93 = 0;
    double gout94 = 0;
    double gout95 = 0;
    double gout96 = 0;
    double gout97 = 0;
    double gout98 = 0;
    double gout99 = 0;
    double gout100 = 0;
    double gout101 = 0;
    double gout102 = 0;
    double gout103 = 0;
    double gout104 = 0;
    double gout105 = 0;
    double gout106 = 0;
    double gout107 = 0;
    double gout108 = 0;
    double gout109 = 0;
    double gout110 = 0;
    double gout111 = 0;
    double gout112 = 0;
    double gout113 = 0;
    double gout114 = 0;
    double gout115 = 0;
    double gout116 = 0;
    double gout117 = 0;
    double gout118 = 0;
    double gout119 = 0;
    double gout120 = 0;
    double gout121 = 0;
    double gout122 = 0;
    double gout123 = 0;
    double gout124 = 0;
    double gout125 = 0;
    double gout126 = 0;
    double gout127 = 0;
    double gout128 = 0;
    double gout129 = 0;
    double gout130 = 0;
    double gout131 = 0;
    double gout132 = 0;
    double gout133 = 0;
    double gout134 = 0;
    double gout135 = 0;
    double gout136 = 0;
    double gout137 = 0;
    double gout138 = 0;
    double gout139 = 0;
    double gout140 = 0;
    double gout141 = 0;
    double gout142 = 0;
    double gout143 = 0;
    double gout144 = 0;
    double gout145 = 0;
    double gout146 = 0;
    double gout147 = 0;
    double gout148 = 0;
    double gout149 = 0;
    double gout150 = 0;
    double gout151 = 0;
    double gout152 = 0;
    double gout153 = 0;
    double gout154 = 0;
    double gout155 = 0;
    double gout156 = 0;
    double gout157 = 0;
    double gout158 = 0;
    double gout159 = 0;
    double gout160 = 0;
    double gout161 = 0;
    double gout162 = 0;
    double gout163 = 0;
    double gout164 = 0;
    double gout165 = 0;
    double gout166 = 0;
    double gout167 = 0;
    double gout168 = 0;
    double gout169 = 0;
    double gout170 = 0;
    double gout171 = 0;
    double gout172 = 0;
    double gout173 = 0;
    double gout174 = 0;
    double gout175 = 0;
    double gout176 = 0;
    double gout177 = 0;
    double gout178 = 0;
    double gout179 = 0;
    double gout180 = 0;
    double gout181 = 0;
    double gout182 = 0;
    double gout183 = 0;
    double gout184 = 0;
    double gout185 = 0;
    double gout186 = 0;
    double gout187 = 0;
    double gout188 = 0;
    double gout189 = 0;
    double gout190 = 0;
    double gout191 = 0;
    double gout192 = 0;
    double gout193 = 0;
    double gout194 = 0;
    double gout195 = 0;
    double gout196 = 0;
    double gout197 = 0;
    double gout198 = 0;
    double gout199 = 0;
    double gout200 = 0;
    double gout201 = 0;
    double gout202 = 0;
    double gout203 = 0;
    double gout204 = 0;
    double gout205 = 0;
    double gout206 = 0;
    double gout207 = 0;
    double gout208 = 0;
    double gout209 = 0;
    double gout210 = 0;
    double gout211 = 0;
    double gout212 = 0;
    double gout213 = 0;
    double gout214 = 0;
    double gout215 = 0;

    double xi = bas_x[ish];
    double yi = bas_y[ish];
    double zi = bas_z[ish];
    double ABx = xi - bas_x[jsh];
    double ABy = yi - bas_y[jsh];
    double ABz = zi - bas_z[jsh];


    prim_ij0 = prim_ij;
    prim_ij1 = prim_ij + nprim_ij;
    prim_kl0 = prim_kl;
    prim_kl1 = prim_kl + nprim_kl;
    double rw[6];
    int irys;
    for (ij = prim_ij0; ij < prim_ij1; ++ij) {
        double alpha = i_exponent[ij];
        double beta = j_exponent[ij];
        double aij = a12[ij];
        double eij = e12[ij];
        double xij = x12[ij];
        double yij = y12[ij];
        double zij = z12[ij];
    for (kl = prim_kl0; kl < prim_kl1; ++kl) {
        double akl = a12[kl];
        double ekl = e12[kl];
        double xkl = x12[kl];
        double ykl = y12[kl];
        double zkl = z12[kl];
        double xijxkl = xij - xkl;
        double yijykl = yij - ykl;
        double zijzkl = zij - zkl;
        double aijkl = aij + akl;
        double a1 = aij * akl;
        double a0 = a1 / aijkl;
        double theta = omega > 0.0 ? omega * omega / (omega * omega + a0) : 1.0; 
        a0 *= theta;
        double x = a0 * (xijxkl * xijxkl + yijykl * yijykl + zijzkl * zijzkl);
        double fac = norm * eij * ekl * sqrt(a0 / (a1 * a1 * a1));
        //double fac = norm * eij * ekl / (sqrt(aijkl) * a1);

        GINTrys_root<3>(x, rw);
        GINTscale_u<3>(rw, theta);
      for (irys = 0; irys < 3; ++irys) {
            double weight0 = rw[irys+3] * fac;
            double root0 = rw[irys];
            double u2 = a0 * root0;
            double tmp4 = .5 / (u2 * aijkl + a1);
            double B00 = u2 * tmp4;
            double tmp1 = 2 * B00;
            double B10 = B00 + tmp4 * akl;
            double tmp2 = tmp1 * akl;
            double C00x = xij - xi - tmp2 * xijxkl;
            double C00y = yij - yi - tmp2 * yijykl;
            double C00z = zij - zi - tmp2 * zijzkl;



            double g0 = B10+C00x*C00x;
            double g1 = 3*B10*C00x;
            double g2 = g1+C00x*C00x*C00x;
            double g3 = ABx+C00x;
            double g4 = C00x*g3;
            double g5 = B10+g4;
            double g6 = ABx*g0;
            double g7 = g1+C00x*C00x*C00x+g6;
            double g8 = 3*B10*B10;
            double g9 = C00x*C00x*C00x*g3;
            double g10 = 2*C00x;
            double g11 = ABx+g10;
            double g12 = 3*B10*C00x*g11;
            double g13 = g8+g9+g12;
            double g14 = B10+g3*g3;
            double g17 = (ABx*ABx*C00x)+g1+C00x*C00x*C00x+(2*ABx*g0);
            double g18 = 6*B10*C00x*C00x;
            double g21 = g8+g18+C00x*C00x*C00x*C00x+(ABx*ABx*g0)+(2*ABx*g2);
            double g23 = 5*B10;
            double g27 = 10*B10;
            double g31 = (6*ABx*B10*B10)+(3*B10*(ABx*ABx+g23)*C00x)+(12*ABx*B10*C00x*C00x)+((ABx*ABx+g27)*C00x*C00x*C00x)+(2*ABx*C00x*C00x*C00x*C00x)+C00x*C00x*C00x*C00x*C00x;
            double g32 = 3*B10;
            double g34 = g3*(g32+g3*g3);
            double g37 = 9*B10;
            double g40 = 2*B10;
            double g44 = (3*B10*(ABx*ABx+B10))+(ABx*(ABx*ABx+g37)*C00x)+(3*(ABx*ABx+g40)*C00x*C00x)+(3*ABx*C00x*C00x*C00x)+C00x*C00x*C00x*C00x;
            double g51 = (15*B10*B10*C00x)+(10*B10*C00x*C00x*C00x)+C00x*C00x*C00x*C00x*C00x+(ABx*ABx*ABx*g0)+(3*ABx*ABx*g2)+(3*ABx*(g8+g18+C00x*C00x*C00x*C00x));
            double g52 = B10+C00y*C00y;
            double g53 = 3*B10*C00y;
            double g54 = g53+C00y*C00y*C00y;
            double g55 = ABy+C00y;
            double g57 = B10+(C00y*g55);
            double g59 = g53+C00y*C00y*C00y+(ABy*g52);
            double g64 = g8+(C00y*C00y*C00y*g55)+(3*B10*C00y*(ABy+(2*C00y)));
            double g65 = B10+g55*g55;
            double g68 = (ABy*ABy*C00y)+g53+C00y*C00y*C00y+(2*ABy*g52);
            double g69 = 6*B10*C00y*C00y;
            double g72 = g8+g69+C00y*C00y*C00y*C00y+(ABy*ABy*g52)+(2*ABy*g54);
            double g80 = (6*ABy*B10*B10)+(3*B10*(ABy*ABy+g23)*C00y)+(12*ABy*B10*C00y*C00y)+((ABy*ABy+g27)*C00y*C00y*C00y)+(2*ABy*C00y*C00y*C00y*C00y)+C00y*C00y*C00y*C00y*C00y;
            double g82 = g55*(g32+g55*g55);
            double g90 = (3*B10*(ABy*ABy+B10))+(ABy*(ABy*ABy+g37)*C00y)+(3*(ABy*ABy+g40)*C00y*C00y)+(3*ABy*C00y*C00y*C00y)+C00y*C00y*C00y*C00y;
            double g97 = (15*B10*B10*C00y)+(10*B10*C00y*C00y*C00y)+C00y*C00y*C00y*C00y*C00y+(ABy*ABy*ABy*g52)+(3*ABy*ABy*g54)+(3*ABy*(g8+g69+C00y*C00y*C00y*C00y));
            double g98 = B10+C00z*C00z;
            double g99 = 3*B10*C00z;
            double g100 = g99+C00z*C00z*C00z;
            double g101 = ABz+C00z;
            double g103 = B10+(C00z*g101);
            double g105 = g99+C00z*C00z*C00z+(ABz*g98);
            double g110 = g8+(C00z*C00z*C00z*g101)+(3*B10*C00z*(ABz+(2*C00z)));
            double g111 = B10+g101*g101;
            double g114 = (ABz*ABz*C00z)+g99+C00z*C00z*C00z+(2*ABz*g98);
            double g115 = 6*B10*C00z*C00z;
            double g118 = g8+g115+C00z*C00z*C00z*C00z+(ABz*ABz*g98)+(2*ABz*g100);
            double g126 = (6*ABz*B10*B10)+(3*B10*(ABz*ABz+g23)*C00z)+(12*ABz*B10*C00z*C00z)+((ABz*ABz+g27)*C00z*C00z*C00z)+(2*ABz*C00z*C00z*C00z*C00z)+C00z*C00z*C00z*C00z*C00z;
            double g128 = g101*(g32+g101*g101);
            double g136 = (3*B10*(ABz*ABz+B10))+(ABz*(ABz*ABz+g37)*C00z)+(3*(ABz*ABz+g40)*C00z*C00z)+(3*ABz*C00z*C00z*C00z)+C00z*C00z*C00z*C00z;
            double g143 = (15*B10*B10*C00z)+(10*B10*C00z*C00z*C00z)+C00z*C00z*C00z*C00z*C00z+(ABz*ABz*ABz*g98)+(3*ABz*ABz*g100)+(3*ABz*(g8+g115+C00z*C00z*C00z*C00z));

            gout0 += (-2*g17 + 2*alpha*g31) * weight0;
            gout1 += (-2*g5 + 2*alpha*g13) * (g55) * weight0;
            gout2 += (-2*g5 + 2*alpha*g13) * (g101) * weight0;
            gout3 += (-2*C00x + 2*alpha*g2) * (g65) * weight0;
            gout4 += (-2*C00x + 2*alpha*g2) * (g55) * (g101) * weight0;
            gout5 += (-2*C00x + 2*alpha*g2) * (g111) * weight0;
            gout6 += (-g14 + 2*alpha*g21) * (C00y) * weight0;
            gout7 += (-g3 + 2*alpha*g7) * (g57) * weight0;
            gout8 += (-g3 + 2*alpha*g7) * (C00y) * (g101) * weight0;
            gout9 += (-1 + 2*alpha*g0) * (g68) * weight0;
            gout10 += (-1 + 2*alpha*g0) * (g57) * (g101) * weight0;
            gout11 += (-1 + 2*alpha*g0) * (C00y) * (g111) * weight0;
            gout12 += (-g14 + 2*alpha*g21) * (C00z) * weight0;
            gout13 += (-g3 + 2*alpha*g7) * (g55) * (C00z) * weight0;
            gout14 += (-g3 + 2*alpha*g7) * (g103) * weight0;
            gout15 += (-1 + 2*alpha*g0) * (g65) * (C00z) * weight0;
            gout16 += (-1 + 2*alpha*g0) * (g55) * (g103) * weight0;
            gout17 += (-1 + 2*alpha*g0) * (g114) * weight0;
            gout18 += (2*alpha*g17) * (g52) * weight0;
            gout19 += (2*alpha*g5) * (g59) * weight0;
            gout20 += (2*alpha*g5) * (g52) * (g101) * weight0;
            gout21 += (2*alpha*C00x) * (g72) * weight0;
            gout22 += (2*alpha*C00x) * (g59) * (g101) * weight0;
            gout23 += (2*alpha*C00x) * (g52) * (g111) * weight0;
            gout24 += (2*alpha*g17) * (C00y) * (C00z) * weight0;
            gout25 += (2*alpha*g5) * (g57) * (C00z) * weight0;
            gout26 += (2*alpha*g5) * (C00y) * (g103) * weight0;
            gout27 += (2*alpha*C00x) * (g68) * (C00z) * weight0;
            gout28 += (2*alpha*C00x) * (g57) * (g103) * weight0;
            gout29 += (2*alpha*C00x) * (C00y) * (g114) * weight0;
            gout30 += (2*alpha*g17) * (g98) * weight0;
            gout31 += (2*alpha*g5) * (g55) * (g98) * weight0;
            gout32 += (2*alpha*g5) * (g105) * weight0;
            gout33 += (2*alpha*C00x) * (g65) * (g98) * weight0;
            gout34 += (2*alpha*C00x) * (g55) * (g105) * weight0;
            gout35 += (2*alpha*C00x) * (g118) * weight0;
            gout36 += (g21) * (2*alpha*C00y) * weight0;
            gout37 += (g7) * (2*alpha*g57) * weight0;
            gout38 += (g7) * (2*alpha*C00y) * (g101) * weight0;
            gout39 += (g0) * (2*alpha*g68) * weight0;
            gout40 += (g0) * (2*alpha*g57) * (g101) * weight0;
            gout41 += (g0) * (2*alpha*C00y) * (g111) * weight0;
            gout42 += (g17) * (-1 + 2*alpha*g52) * weight0;
            gout43 += (g5) * (-g55 + 2*alpha*g59) * weight0;
            gout44 += (g5) * (-1 + 2*alpha*g52) * (g101) * weight0;
            gout45 += (C00x) * (-g65 + 2*alpha*g72) * weight0;
            gout46 += (C00x) * (-g55 + 2*alpha*g59) * (g101) * weight0;
            gout47 += (C00x) * (-1 + 2*alpha*g52) * (g111) * weight0;
            gout48 += (g17) * (2*alpha*C00y) * (C00z) * weight0;
            gout49 += (g5) * (2*alpha*g57) * (C00z) * weight0;
            gout50 += (g5) * (2*alpha*C00y) * (g103) * weight0;
            gout51 += (C00x) * (2*alpha*g68) * (C00z) * weight0;
            gout52 += (C00x) * (2*alpha*g57) * (g103) * weight0;
            gout53 += (C00x) * (2*alpha*C00y) * (g114) * weight0;
            gout54 += (g14) * (-2*C00y + 2*alpha*g54) * weight0;
            gout55 += (g3) * (-2*g57 + 2*alpha*g64) * weight0;
            gout56 += (g3) * (-2*C00y + 2*alpha*g54) * (g101) * weight0;
            gout57 += (-2*g68 + 2*alpha*g80) * weight0;
            gout58 += (-2*g57 + 2*alpha*g64) * (g101) * weight0;
            gout59 += (-2*C00y + 2*alpha*g54) * (g111) * weight0;
            gout60 += (g14) * (-1 + 2*alpha*g52) * (C00z) * weight0;
            gout61 += (g3) * (-g55 + 2*alpha*g59) * (C00z) * weight0;
            gout62 += (g3) * (-1 + 2*alpha*g52) * (g103) * weight0;
            gout63 += (-g65 + 2*alpha*g72) * (C00z) * weight0;
            gout64 += (-g55 + 2*alpha*g59) * (g103) * weight0;
            gout65 += (-1 + 2*alpha*g52) * (g114) * weight0;
            gout66 += (g14) * (2*alpha*C00y) * (g98) * weight0;
            gout67 += (g3) * (2*alpha*g57) * (g98) * weight0;
            gout68 += (g3) * (2*alpha*C00y) * (g105) * weight0;
            gout69 += (2*alpha*g68) * (g98) * weight0;
            gout70 += (2*alpha*g57) * (g105) * weight0;
            gout71 += (2*alpha*C00y) * (g118) * weight0;
            gout72 += (g21) * (2*alpha*C00z) * weight0;
            gout73 += (g7) * (g55) * (2*alpha*C00z) * weight0;
            gout74 += (g7) * (2*alpha*g103) * weight0;
            gout75 += (g0) * (g65) * (2*alpha*C00z) * weight0;
            gout76 += (g0) * (g55) * (2*alpha*g103) * weight0;
            gout77 += (g0) * (2*alpha*g114) * weight0;
            gout78 += (g17) * (C00y) * (2*alpha*C00z) * weight0;
            gout79 += (g5) * (g57) * (2*alpha*C00z) * weight0;
            gout80 += (g5) * (C00y) * (2*alpha*g103) * weight0;
            gout81 += (C00x) * (g68) * (2*alpha*C00z) * weight0;
            gout82 += (C00x) * (g57) * (2*alpha*g103) * weight0;
            gout83 += (C00x) * (C00y) * (2*alpha*g114) * weight0;
            gout84 += (g17) * (-1 + 2*alpha*g98) * weight0;
            gout85 += (g5) * (g55) * (-1 + 2*alpha*g98) * weight0;
            gout86 += (g5) * (-g101 + 2*alpha*g105) * weight0;
            gout87 += (C00x) * (g65) * (-1 + 2*alpha*g98) * weight0;
            gout88 += (C00x) * (g55) * (-g101 + 2*alpha*g105) * weight0;
            gout89 += (C00x) * (-g111 + 2*alpha*g118) * weight0;
            gout90 += (g14) * (g52) * (2*alpha*C00z) * weight0;
            gout91 += (g3) * (g59) * (2*alpha*C00z) * weight0;
            gout92 += (g3) * (g52) * (2*alpha*g103) * weight0;
            gout93 += (g72) * (2*alpha*C00z) * weight0;
            gout94 += (g59) * (2*alpha*g103) * weight0;
            gout95 += (g52) * (2*alpha*g114) * weight0;
            gout96 += (g14) * (C00y) * (-1 + 2*alpha*g98) * weight0;
            gout97 += (g3) * (g57) * (-1 + 2*alpha*g98) * weight0;
            gout98 += (g3) * (C00y) * (-g101 + 2*alpha*g105) * weight0;
            gout99 += (g68) * (-1 + 2*alpha*g98) * weight0;
            gout100 += (g57) * (-g101 + 2*alpha*g105) * weight0;
            gout101 += (C00y) * (-g111 + 2*alpha*g118) * weight0;
            gout102 += (g14) * (-2*C00z + 2*alpha*g100) * weight0;
            gout103 += (g3) * (g55) * (-2*C00z + 2*alpha*g100) * weight0;
            gout104 += (g3) * (-2*g103 + 2*alpha*g110) * weight0;
            gout105 += (g65) * (-2*C00z + 2*alpha*g100) * weight0;
            gout106 += (g55) * (-2*g103 + 2*alpha*g110) * weight0;
            gout107 += (-2*g114 + 2*alpha*g126) * weight0;
            gout108 += (-2*g7 + 2*beta*g51) * weight0;
            gout109 += (-g0 + 2*beta*g21) * (g55) * weight0;
            gout110 += (-g0 + 2*beta*g21) * (g101) * weight0;
            gout111 += (2*beta*g7) * (g65) * weight0;
            gout112 += (2*beta*g7) * (g55) * (g101) * weight0;
            gout113 += (2*beta*g7) * (g111) * weight0;
            gout114 += (-2*g5 + 2*beta*g44) * (C00y) * weight0;
            gout115 += (-C00x + 2*beta*g17) * (g57) * weight0;
            gout116 += (-C00x + 2*beta*g17) * (C00y) * (g101) * weight0;
            gout117 += (2*beta*g5) * (g68) * weight0;
            gout118 += (2*beta*g5) * (g57) * (g101) * weight0;
            gout119 += (2*beta*g5) * (C00y) * (g111) * weight0;
            gout120 += (-2*g5 + 2*beta*g44) * (C00z) * weight0;
            gout121 += (-C00x + 2*beta*g17) * (g55) * (C00z) * weight0;
            gout122 += (-C00x + 2*beta*g17) * (g103) * weight0;
            gout123 += (2*beta*g5) * (g65) * (C00z) * weight0;
            gout124 += (2*beta*g5) * (g55) * (g103) * weight0;
            gout125 += (2*beta*g5) * (g114) * weight0;
            gout126 += (-2*g3 + 2*beta*g34) * (g52) * weight0;
            gout127 += (-1 + 2*beta*g14) * (g59) * weight0;
            gout128 += (-1 + 2*beta*g14) * (g52) * (g101) * weight0;
            gout129 += (2*beta*g3) * (g72) * weight0;
            gout130 += (2*beta*g3) * (g59) * (g101) * weight0;
            gout131 += (2*beta*g3) * (g52) * (g111) * weight0;
            gout132 += (-2*g3 + 2*beta*g34) * (C00y) * (C00z) * weight0;
            gout133 += (-1 + 2*beta*g14) * (g57) * (C00z) * weight0;
            gout134 += (-1 + 2*beta*g14) * (C00y) * (g103) * weight0;
            gout135 += (2*beta*g3) * (g68) * (C00z) * weight0;
            gout136 += (2*beta*g3) * (g57) * (g103) * weight0;
            gout137 += (2*beta*g3) * (C00y) * (g114) * weight0;
            gout138 += (-2*g3 + 2*beta*g34) * (g98) * weight0;
            gout139 += (-1 + 2*beta*g14) * (g55) * (g98) * weight0;
            gout140 += (-1 + 2*beta*g14) * (g105) * weight0;
            gout141 += (2*beta*g3) * (g65) * (g98) * weight0;
            gout142 += (2*beta*g3) * (g55) * (g105) * weight0;
            gout143 += (2*beta*g3) * (g118) * weight0;
            gout144 += (g21) * (2*beta*g55) * weight0;
            gout145 += (g7) * (-1 + 2*beta*g65) * weight0;
            gout146 += (g7) * (2*beta*g55) * (g101) * weight0;
            gout147 += (g0) * (-2*g55 + 2*beta*g82) * weight0;
            gout148 += (g0) * (-1 + 2*beta*g65) * (g101) * weight0;
            gout149 += (g0) * (2*beta*g55) * (g111) * weight0;
            gout150 += (g17) * (2*beta*g57) * weight0;
            gout151 += (g5) * (-C00y + 2*beta*g68) * weight0;
            gout152 += (g5) * (2*beta*g57) * (g101) * weight0;
            gout153 += (C00x) * (-2*g57 + 2*beta*g90) * weight0;
            gout154 += (C00x) * (-C00y + 2*beta*g68) * (g101) * weight0;
            gout155 += (C00x) * (2*beta*g57) * (g111) * weight0;
            gout156 += (g17) * (2*beta*g55) * (C00z) * weight0;
            gout157 += (g5) * (-1 + 2*beta*g65) * (C00z) * weight0;
            gout158 += (g5) * (2*beta*g55) * (g103) * weight0;
            gout159 += (C00x) * (-2*g55 + 2*beta*g82) * (C00z) * weight0;
            gout160 += (C00x) * (-1 + 2*beta*g65) * (g103) * weight0;
            gout161 += (C00x) * (2*beta*g55) * (g114) * weight0;
            gout162 += (g14) * (2*beta*g59) * weight0;
            gout163 += (g3) * (-g52 + 2*beta*g72) * weight0;
            gout164 += (g3) * (2*beta*g59) * (g101) * weight0;
            gout165 += (-2*g59 + 2*beta*g97) * weight0;
            gout166 += (-g52 + 2*beta*g72) * (g101) * weight0;
            gout167 += (2*beta*g59) * (g111) * weight0;
            gout168 += (g14) * (2*beta*g57) * (C00z) * weight0;
            gout169 += (g3) * (-C00y + 2*beta*g68) * (C00z) * weight0;
            gout170 += (g3) * (2*beta*g57) * (g103) * weight0;
            gout171 += (-2*g57 + 2*beta*g90) * (C00z) * weight0;
            gout172 += (-C00y + 2*beta*g68) * (g103) * weight0;
            gout173 += (2*beta*g57) * (g114) * weight0;
            gout174 += (g14) * (2*beta*g55) * (g98) * weight0;
            gout175 += (g3) * (-1 + 2*beta*g65) * (g98) * weight0;
            gout176 += (g3) * (2*beta*g55) * (g105) * weight0;
            gout177 += (-2*g55 + 2*beta*g82) * (g98) * weight0;
            gout178 += (-1 + 2*beta*g65) * (g105) * weight0;
            gout179 += (2*beta*g55) * (g118) * weight0;
            gout180 += (g21) * (2*beta*g101) * weight0;
            gout181 += (g7) * (g55) * (2*beta*g101) * weight0;
            gout182 += (g7) * (-1 + 2*beta*g111) * weight0;
            gout183 += (g0) * (g65) * (2*beta*g101) * weight0;
            gout184 += (g0) * (g55) * (-1 + 2*beta*g111) * weight0;
            gout185 += (g0) * (-2*g101 + 2*beta*g128) * weight0;
            gout186 += (g17) * (C00y) * (2*beta*g101) * weight0;
            gout187 += (g5) * (g57) * (2*beta*g101) * weight0;
            gout188 += (g5) * (C00y) * (-1 + 2*beta*g111) * weight0;
            gout189 += (C00x) * (g68) * (2*beta*g101) * weight0;
            gout190 += (C00x) * (g57) * (-1 + 2*beta*g111) * weight0;
            gout191 += (C00x) * (C00y) * (-2*g101 + 2*beta*g128) * weight0;
            gout192 += (g17) * (2*beta*g103) * weight0;
            gout193 += (g5) * (g55) * (2*beta*g103) * weight0;
            gout194 += (g5) * (-C00z + 2*beta*g114) * weight0;
            gout195 += (C00x) * (g65) * (2*beta*g103) * weight0;
            gout196 += (C00x) * (g55) * (-C00z + 2*beta*g114) * weight0;
            gout197 += (C00x) * (-2*g103 + 2*beta*g136) * weight0;
            gout198 += (g14) * (g52) * (2*beta*g101) * weight0;
            gout199 += (g3) * (g59) * (2*beta*g101) * weight0;
            gout200 += (g3) * (g52) * (-1 + 2*beta*g111) * weight0;
            gout201 += (g72) * (2*beta*g101) * weight0;
            gout202 += (g59) * (-1 + 2*beta*g111) * weight0;
            gout203 += (g52) * (-2*g101 + 2*beta*g128) * weight0;
            gout204 += (g14) * (C00y) * (2*beta*g103) * weight0;
            gout205 += (g3) * (g57) * (2*beta*g103) * weight0;
            gout206 += (g3) * (C00y) * (-C00z + 2*beta*g114) * weight0;
            gout207 += (g68) * (2*beta*g103) * weight0;
            gout208 += (g57) * (-C00z + 2*beta*g114) * weight0;
            gout209 += (C00y) * (-2*g103 + 2*beta*g136) * weight0;
            gout210 += (g14) * (2*beta*g105) * weight0;
            gout211 += (g3) * (g55) * (2*beta*g105) * weight0;
            gout212 += (g3) * (-g98 + 2*beta*g118) * weight0;
            gout213 += (g65) * (2*beta*g105) * weight0;
            gout214 += (g55) * (-g98 + 2*beta*g118) * weight0;
            gout215 += (-2*g105 + 2*beta*g143) * weight0;
        }
    } }

    int *ao_loc = c_bpcache.ao_loc;
    int i0 = ao_loc[ish];
    int j0 = ao_loc[jsh];
    int k0 = ao_loc[ksh];
    int l0 = ao_loc[lsh];
    int n_dm = jk.n_dm;
    int nao = jk.nao;
    size_t nao2 = nao * nao;
    double* __restrict__ dm = jk.dm;
    double *vj = jk.vj;
    double *vk = jk.vk;
    double d_0, d_1, d_2, d_3, d_4, d_5;

    for (int i_dm = 0; i_dm < n_dm; ++i_dm) {
        if (vj != NULL) {
            d_0 = dm[(k0+0)+nao*(l0+0)];
            atomicAdd(vj+(i0+0)+nao*(j0+0), gout0*d_0);
            atomicAdd(vj+(i0+0)+nao*(j0+1), gout1*d_0);
            atomicAdd(vj+(i0+0)+nao*(j0+2), gout2*d_0);
            atomicAdd(vj+(i0+0)+nao*(j0+3), gout3*d_0);
            atomicAdd(vj+(i0+0)+nao*(j0+4), gout4*d_0);
            atomicAdd(vj+(i0+0)+nao*(j0+5), gout5*d_0);
            atomicAdd(vj+(i0+1)+nao*(j0+0), gout6*d_0);
            atomicAdd(vj+(i0+1)+nao*(j0+1), gout7*d_0);
            atomicAdd(vj+(i0+1)+nao*(j0+2), gout8*d_0);
            atomicAdd(vj+(i0+1)+nao*(j0+3), gout9*d_0);
            atomicAdd(vj+(i0+1)+nao*(j0+4), gout10*d_0);
            atomicAdd(vj+(i0+1)+nao*(j0+5), gout11*d_0);
            atomicAdd(vj+(i0+2)+nao*(j0+0), gout12*d_0);
            atomicAdd(vj+(i0+2)+nao*(j0+1), gout13*d_0);
            atomicAdd(vj+(i0+2)+nao*(j0+2), gout14*d_0);
            atomicAdd(vj+(i0+2)+nao*(j0+3), gout15*d_0);
            atomicAdd(vj+(i0+2)+nao*(j0+4), gout16*d_0);
            atomicAdd(vj+(i0+2)+nao*(j0+5), gout17*d_0);
            atomicAdd(vj+(i0+3)+nao*(j0+0), gout18*d_0);
            atomicAdd(vj+(i0+3)+nao*(j0+1), gout19*d_0);
            atomicAdd(vj+(i0+3)+nao*(j0+2), gout20*d_0);
            atomicAdd(vj+(i0+3)+nao*(j0+3), gout21*d_0);
            atomicAdd(vj+(i0+3)+nao*(j0+4), gout22*d_0);
            atomicAdd(vj+(i0+3)+nao*(j0+5), gout23*d_0);
            atomicAdd(vj+(i0+4)+nao*(j0+0), gout24*d_0);
            atomicAdd(vj+(i0+4)+nao*(j0+1), gout25*d_0);
            atomicAdd(vj+(i0+4)+nao*(j0+2), gout26*d_0);
            atomicAdd(vj+(i0+4)+nao*(j0+3), gout27*d_0);
            atomicAdd(vj+(i0+4)+nao*(j0+4), gout28*d_0);
            atomicAdd(vj+(i0+4)+nao*(j0+5), gout29*d_0);
            atomicAdd(vj+(i0+5)+nao*(j0+0), gout30*d_0);
            atomicAdd(vj+(i0+5)+nao*(j0+1), gout31*d_0);
            atomicAdd(vj+(i0+5)+nao*(j0+2), gout32*d_0);
            atomicAdd(vj+(i0+5)+nao*(j0+3), gout33*d_0);
            atomicAdd(vj+(i0+5)+nao*(j0+4), gout34*d_0);
            atomicAdd(vj+(i0+5)+nao*(j0+5), gout35*d_0);
            atomicAdd(vj+(i0+0)+nao*(j0+0)+nao2, gout36*d_0);
            atomicAdd(vj+(i0+0)+nao*(j0+1)+nao2, gout37*d_0);
            atomicAdd(vj+(i0+0)+nao*(j0+2)+nao2, gout38*d_0);
            atomicAdd(vj+(i0+0)+nao*(j0+3)+nao2, gout39*d_0);
            atomicAdd(vj+(i0+0)+nao*(j0+4)+nao2, gout40*d_0);
            atomicAdd(vj+(i0+0)+nao*(j0+5)+nao2, gout41*d_0);
            atomicAdd(vj+(i0+1)+nao*(j0+0)+nao2, gout42*d_0);
            atomicAdd(vj+(i0+1)+nao*(j0+1)+nao2, gout43*d_0);
            atomicAdd(vj+(i0+1)+nao*(j0+2)+nao2, gout44*d_0);
            atomicAdd(vj+(i0+1)+nao*(j0+3)+nao2, gout45*d_0);
            atomicAdd(vj+(i0+1)+nao*(j0+4)+nao2, gout46*d_0);
            atomicAdd(vj+(i0+1)+nao*(j0+5)+nao2, gout47*d_0);
            atomicAdd(vj+(i0+2)+nao*(j0+0)+nao2, gout48*d_0);
            atomicAdd(vj+(i0+2)+nao*(j0+1)+nao2, gout49*d_0);
            atomicAdd(vj+(i0+2)+nao*(j0+2)+nao2, gout50*d_0);
            atomicAdd(vj+(i0+2)+nao*(j0+3)+nao2, gout51*d_0);
            atomicAdd(vj+(i0+2)+nao*(j0+4)+nao2, gout52*d_0);
            atomicAdd(vj+(i0+2)+nao*(j0+5)+nao2, gout53*d_0);
            atomicAdd(vj+(i0+3)+nao*(j0+0)+nao2, gout54*d_0);
            atomicAdd(vj+(i0+3)+nao*(j0+1)+nao2, gout55*d_0);
            atomicAdd(vj+(i0+3)+nao*(j0+2)+nao2, gout56*d_0);
            atomicAdd(vj+(i0+3)+nao*(j0+3)+nao2, gout57*d_0);
            atomicAdd(vj+(i0+3)+nao*(j0+4)+nao2, gout58*d_0);
            atomicAdd(vj+(i0+3)+nao*(j0+5)+nao2, gout59*d_0);
            atomicAdd(vj+(i0+4)+nao*(j0+0)+nao2, gout60*d_0);
            atomicAdd(vj+(i0+4)+nao*(j0+1)+nao2, gout61*d_0);
            atomicAdd(vj+(i0+4)+nao*(j0+2)+nao2, gout62*d_0);
            atomicAdd(vj+(i0+4)+nao*(j0+3)+nao2, gout63*d_0);
            atomicAdd(vj+(i0+4)+nao*(j0+4)+nao2, gout64*d_0);
            atomicAdd(vj+(i0+4)+nao*(j0+5)+nao2, gout65*d_0);
            atomicAdd(vj+(i0+5)+nao*(j0+0)+nao2, gout66*d_0);
            atomicAdd(vj+(i0+5)+nao*(j0+1)+nao2, gout67*d_0);
            atomicAdd(vj+(i0+5)+nao*(j0+2)+nao2, gout68*d_0);
            atomicAdd(vj+(i0+5)+nao*(j0+3)+nao2, gout69*d_0);
            atomicAdd(vj+(i0+5)+nao*(j0+4)+nao2, gout70*d_0);
            atomicAdd(vj+(i0+5)+nao*(j0+5)+nao2, gout71*d_0);
            atomicAdd(vj+(i0+0)+nao*(j0+0)+2*nao2, gout72*d_0);
            atomicAdd(vj+(i0+0)+nao*(j0+1)+2*nao2, gout73*d_0);
            atomicAdd(vj+(i0+0)+nao*(j0+2)+2*nao2, gout74*d_0);
            atomicAdd(vj+(i0+0)+nao*(j0+3)+2*nao2, gout75*d_0);
            atomicAdd(vj+(i0+0)+nao*(j0+4)+2*nao2, gout76*d_0);
            atomicAdd(vj+(i0+0)+nao*(j0+5)+2*nao2, gout77*d_0);
            atomicAdd(vj+(i0+1)+nao*(j0+0)+2*nao2, gout78*d_0);
            atomicAdd(vj+(i0+1)+nao*(j0+1)+2*nao2, gout79*d_0);
            atomicAdd(vj+(i0+1)+nao*(j0+2)+2*nao2, gout80*d_0);
            atomicAdd(vj+(i0+1)+nao*(j0+3)+2*nao2, gout81*d_0);
            atomicAdd(vj+(i0+1)+nao*(j0+4)+2*nao2, gout82*d_0);
            atomicAdd(vj+(i0+1)+nao*(j0+5)+2*nao2, gout83*d_0);
            atomicAdd(vj+(i0+2)+nao*(j0+0)+2*nao2, gout84*d_0);
            atomicAdd(vj+(i0+2)+nao*(j0+1)+2*nao2, gout85*d_0);
            atomicAdd(vj+(i0+2)+nao*(j0+2)+2*nao2, gout86*d_0);
            atomicAdd(vj+(i0+2)+nao*(j0+3)+2*nao2, gout87*d_0);
            atomicAdd(vj+(i0+2)+nao*(j0+4)+2*nao2, gout88*d_0);
            atomicAdd(vj+(i0+2)+nao*(j0+5)+2*nao2, gout89*d_0);
            atomicAdd(vj+(i0+3)+nao*(j0+0)+2*nao2, gout90*d_0);
            atomicAdd(vj+(i0+3)+nao*(j0+1)+2*nao2, gout91*d_0);
            atomicAdd(vj+(i0+3)+nao*(j0+2)+2*nao2, gout92*d_0);
            atomicAdd(vj+(i0+3)+nao*(j0+3)+2*nao2, gout93*d_0);
            atomicAdd(vj+(i0+3)+nao*(j0+4)+2*nao2, gout94*d_0);
            atomicAdd(vj+(i0+3)+nao*(j0+5)+2*nao2, gout95*d_0);
            atomicAdd(vj+(i0+4)+nao*(j0+0)+2*nao2, gout96*d_0);
            atomicAdd(vj+(i0+4)+nao*(j0+1)+2*nao2, gout97*d_0);
            atomicAdd(vj+(i0+4)+nao*(j0+2)+2*nao2, gout98*d_0);
            atomicAdd(vj+(i0+4)+nao*(j0+3)+2*nao2, gout99*d_0);
            atomicAdd(vj+(i0+4)+nao*(j0+4)+2*nao2, gout100*d_0);
            atomicAdd(vj+(i0+4)+nao*(j0+5)+2*nao2, gout101*d_0);
            atomicAdd(vj+(i0+5)+nao*(j0+0)+2*nao2, gout102*d_0);
            atomicAdd(vj+(i0+5)+nao*(j0+1)+2*nao2, gout103*d_0);
            atomicAdd(vj+(i0+5)+nao*(j0+2)+2*nao2, gout104*d_0);
            atomicAdd(vj+(i0+5)+nao*(j0+3)+2*nao2, gout105*d_0);
            atomicAdd(vj+(i0+5)+nao*(j0+4)+2*nao2, gout106*d_0);
            atomicAdd(vj+(i0+5)+nao*(j0+5)+2*nao2, gout107*d_0);
            atomicAdd(vj+nao*(i0+0)+(j0+0), gout108*d_0);
            atomicAdd(vj+nao*(i0+0)+(j0+1), gout109*d_0);
            atomicAdd(vj+nao*(i0+0)+(j0+2), gout110*d_0);
            atomicAdd(vj+nao*(i0+0)+(j0+3), gout111*d_0);
            atomicAdd(vj+nao*(i0+0)+(j0+4), gout112*d_0);
            atomicAdd(vj+nao*(i0+0)+(j0+5), gout113*d_0);
            atomicAdd(vj+nao*(i0+1)+(j0+0), gout114*d_0);
            atomicAdd(vj+nao*(i0+1)+(j0+1), gout115*d_0);
            atomicAdd(vj+nao*(i0+1)+(j0+2), gout116*d_0);
            atomicAdd(vj+nao*(i0+1)+(j0+3), gout117*d_0);
            atomicAdd(vj+nao*(i0+1)+(j0+4), gout118*d_0);
            atomicAdd(vj+nao*(i0+1)+(j0+5), gout119*d_0);
            atomicAdd(vj+nao*(i0+2)+(j0+0), gout120*d_0);
            atomicAdd(vj+nao*(i0+2)+(j0+1), gout121*d_0);
            atomicAdd(vj+nao*(i0+2)+(j0+2), gout122*d_0);
            atomicAdd(vj+nao*(i0+2)+(j0+3), gout123*d_0);
            atomicAdd(vj+nao*(i0+2)+(j0+4), gout124*d_0);
            atomicAdd(vj+nao*(i0+2)+(j0+5), gout125*d_0);
            atomicAdd(vj+nao*(i0+3)+(j0+0), gout126*d_0);
            atomicAdd(vj+nao*(i0+3)+(j0+1), gout127*d_0);
            atomicAdd(vj+nao*(i0+3)+(j0+2), gout128*d_0);
            atomicAdd(vj+nao*(i0+3)+(j0+3), gout129*d_0);
            atomicAdd(vj+nao*(i0+3)+(j0+4), gout130*d_0);
            atomicAdd(vj+nao*(i0+3)+(j0+5), gout131*d_0);
            atomicAdd(vj+nao*(i0+4)+(j0+0), gout132*d_0);
            atomicAdd(vj+nao*(i0+4)+(j0+1), gout133*d_0);
            atomicAdd(vj+nao*(i0+4)+(j0+2), gout134*d_0);
            atomicAdd(vj+nao*(i0+4)+(j0+3), gout135*d_0);
            atomicAdd(vj+nao*(i0+4)+(j0+4), gout136*d_0);
            atomicAdd(vj+nao*(i0+4)+(j0+5), gout137*d_0);
            atomicAdd(vj+nao*(i0+5)+(j0+0), gout138*d_0);
            atomicAdd(vj+nao*(i0+5)+(j0+1), gout139*d_0);
            atomicAdd(vj+nao*(i0+5)+(j0+2), gout140*d_0);
            atomicAdd(vj+nao*(i0+5)+(j0+3), gout141*d_0);
            atomicAdd(vj+nao*(i0+5)+(j0+4), gout142*d_0);
            atomicAdd(vj+nao*(i0+5)+(j0+5), gout143*d_0);
            atomicAdd(vj+nao*(i0+0)+(j0+0)+nao2, gout144*d_0);
            atomicAdd(vj+nao*(i0+0)+(j0+1)+nao2, gout145*d_0);
            atomicAdd(vj+nao*(i0+0)+(j0+2)+nao2, gout146*d_0);
            atomicAdd(vj+nao*(i0+0)+(j0+3)+nao2, gout147*d_0);
            atomicAdd(vj+nao*(i0+0)+(j0+4)+nao2, gout148*d_0);
            atomicAdd(vj+nao*(i0+0)+(j0+5)+nao2, gout149*d_0);
            atomicAdd(vj+nao*(i0+1)+(j0+0)+nao2, gout150*d_0);
            atomicAdd(vj+nao*(i0+1)+(j0+1)+nao2, gout151*d_0);
            atomicAdd(vj+nao*(i0+1)+(j0+2)+nao2, gout152*d_0);
            atomicAdd(vj+nao*(i0+1)+(j0+3)+nao2, gout153*d_0);
            atomicAdd(vj+nao*(i0+1)+(j0+4)+nao2, gout154*d_0);
            atomicAdd(vj+nao*(i0+1)+(j0+5)+nao2, gout155*d_0);
            atomicAdd(vj+nao*(i0+2)+(j0+0)+nao2, gout156*d_0);
            atomicAdd(vj+nao*(i0+2)+(j0+1)+nao2, gout157*d_0);
            atomicAdd(vj+nao*(i0+2)+(j0+2)+nao2, gout158*d_0);
            atomicAdd(vj+nao*(i0+2)+(j0+3)+nao2, gout159*d_0);
            atomicAdd(vj+nao*(i0+2)+(j0+4)+nao2, gout160*d_0);
            atomicAdd(vj+nao*(i0+2)+(j0+5)+nao2, gout161*d_0);
            atomicAdd(vj+nao*(i0+3)+(j0+0)+nao2, gout162*d_0);
            atomicAdd(vj+nao*(i0+3)+(j0+1)+nao2, gout163*d_0);
            atomicAdd(vj+nao*(i0+3)+(j0+2)+nao2, gout164*d_0);
            atomicAdd(vj+nao*(i0+3)+(j0+3)+nao2, gout165*d_0);
            atomicAdd(vj+nao*(i0+3)+(j0+4)+nao2, gout166*d_0);
            atomicAdd(vj+nao*(i0+3)+(j0+5)+nao2, gout167*d_0);
            atomicAdd(vj+nao*(i0+4)+(j0+0)+nao2, gout168*d_0);
            atomicAdd(vj+nao*(i0+4)+(j0+1)+nao2, gout169*d_0);
            atomicAdd(vj+nao*(i0+4)+(j0+2)+nao2, gout170*d_0);
            atomicAdd(vj+nao*(i0+4)+(j0+3)+nao2, gout171*d_0);
            atomicAdd(vj+nao*(i0+4)+(j0+4)+nao2, gout172*d_0);
            atomicAdd(vj+nao*(i0+4)+(j0+5)+nao2, gout173*d_0);
            atomicAdd(vj+nao*(i0+5)+(j0+0)+nao2, gout174*d_0);
            atomicAdd(vj+nao*(i0+5)+(j0+1)+nao2, gout175*d_0);
            atomicAdd(vj+nao*(i0+5)+(j0+2)+nao2, gout176*d_0);
            atomicAdd(vj+nao*(i0+5)+(j0+3)+nao2, gout177*d_0);
            atomicAdd(vj+nao*(i0+5)+(j0+4)+nao2, gout178*d_0);
            atomicAdd(vj+nao*(i0+5)+(j0+5)+nao2, gout179*d_0);
            atomicAdd(vj+nao*(i0+0)+(j0+0)+2*nao2, gout180*d_0);
            atomicAdd(vj+nao*(i0+0)+(j0+1)+2*nao2, gout181*d_0);
            atomicAdd(vj+nao*(i0+0)+(j0+2)+2*nao2, gout182*d_0);
            atomicAdd(vj+nao*(i0+0)+(j0+3)+2*nao2, gout183*d_0);
            atomicAdd(vj+nao*(i0+0)+(j0+4)+2*nao2, gout184*d_0);
            atomicAdd(vj+nao*(i0+0)+(j0+5)+2*nao2, gout185*d_0);
            atomicAdd(vj+nao*(i0+1)+(j0+0)+2*nao2, gout186*d_0);
            atomicAdd(vj+nao*(i0+1)+(j0+1)+2*nao2, gout187*d_0);
            atomicAdd(vj+nao*(i0+1)+(j0+2)+2*nao2, gout188*d_0);
            atomicAdd(vj+nao*(i0+1)+(j0+3)+2*nao2, gout189*d_0);
            atomicAdd(vj+nao*(i0+1)+(j0+4)+2*nao2, gout190*d_0);
            atomicAdd(vj+nao*(i0+1)+(j0+5)+2*nao2, gout191*d_0);
            atomicAdd(vj+nao*(i0+2)+(j0+0)+2*nao2, gout192*d_0);
            atomicAdd(vj+nao*(i0+2)+(j0+1)+2*nao2, gout193*d_0);
            atomicAdd(vj+nao*(i0+2)+(j0+2)+2*nao2, gout194*d_0);
            atomicAdd(vj+nao*(i0+2)+(j0+3)+2*nao2, gout195*d_0);
            atomicAdd(vj+nao*(i0+2)+(j0+4)+2*nao2, gout196*d_0);
            atomicAdd(vj+nao*(i0+2)+(j0+5)+2*nao2, gout197*d_0);
            atomicAdd(vj+nao*(i0+3)+(j0+0)+2*nao2, gout198*d_0);
            atomicAdd(vj+nao*(i0+3)+(j0+1)+2*nao2, gout199*d_0);
            atomicAdd(vj+nao*(i0+3)+(j0+2)+2*nao2, gout200*d_0);
            atomicAdd(vj+nao*(i0+3)+(j0+3)+2*nao2, gout201*d_0);
            atomicAdd(vj+nao*(i0+3)+(j0+4)+2*nao2, gout202*d_0);
            atomicAdd(vj+nao*(i0+3)+(j0+5)+2*nao2, gout203*d_0);
            atomicAdd(vj+nao*(i0+4)+(j0+0)+2*nao2, gout204*d_0);
            atomicAdd(vj+nao*(i0+4)+(j0+1)+2*nao2, gout205*d_0);
            atomicAdd(vj+nao*(i0+4)+(j0+2)+2*nao2, gout206*d_0);
            atomicAdd(vj+nao*(i0+4)+(j0+3)+2*nao2, gout207*d_0);
            atomicAdd(vj+nao*(i0+4)+(j0+4)+2*nao2, gout208*d_0);
            atomicAdd(vj+nao*(i0+4)+(j0+5)+2*nao2, gout209*d_0);
            atomicAdd(vj+nao*(i0+5)+(j0+0)+2*nao2, gout210*d_0);
            atomicAdd(vj+nao*(i0+5)+(j0+1)+2*nao2, gout211*d_0);
            atomicAdd(vj+nao*(i0+5)+(j0+2)+2*nao2, gout212*d_0);
            atomicAdd(vj+nao*(i0+5)+(j0+3)+2*nao2, gout213*d_0);
            atomicAdd(vj+nao*(i0+5)+(j0+4)+2*nao2, gout214*d_0);
            atomicAdd(vj+nao*(i0+5)+(j0+5)+2*nao2, gout215*d_0);
            vj += 3*nao2;
        }
        if (vk != NULL) {
            // ijkl, jk -> il
            d_0 = dm[(j0+0)+nao*(k0+0)];
            d_1 = dm[(j0+1)+nao*(k0+0)];
            d_2 = dm[(j0+2)+nao*(k0+0)];
            d_3 = dm[(j0+3)+nao*(k0+0)];
            d_4 = dm[(j0+4)+nao*(k0+0)];
            d_5 = dm[(j0+5)+nao*(k0+0)];
            atomicAdd(vk+(i0+0)+nao*(l0+0), gout0*d_0+gout1*d_1+gout2*d_2+gout3*d_3+gout4*d_4+gout5*d_5);
            atomicAdd(vk+(i0+1)+nao*(l0+0), gout6*d_0+gout7*d_1+gout8*d_2+gout9*d_3+gout10*d_4+gout11*d_5);
            atomicAdd(vk+(i0+2)+nao*(l0+0), gout12*d_0+gout13*d_1+gout14*d_2+gout15*d_3+gout16*d_4+gout17*d_5);
            atomicAdd(vk+(i0+3)+nao*(l0+0), gout18*d_0+gout19*d_1+gout20*d_2+gout21*d_3+gout22*d_4+gout23*d_5);
            atomicAdd(vk+(i0+4)+nao*(l0+0), gout24*d_0+gout25*d_1+gout26*d_2+gout27*d_3+gout28*d_4+gout29*d_5);
            atomicAdd(vk+(i0+5)+nao*(l0+0), gout30*d_0+gout31*d_1+gout32*d_2+gout33*d_3+gout34*d_4+gout35*d_5);
            atomicAdd(vk+(i0+0)+nao*(l0+0)+nao2, gout36*d_0+gout37*d_1+gout38*d_2+gout39*d_3+gout40*d_4+gout41*d_5);
            atomicAdd(vk+(i0+1)+nao*(l0+0)+nao2, gout42*d_0+gout43*d_1+gout44*d_2+gout45*d_3+gout46*d_4+gout47*d_5);
            atomicAdd(vk+(i0+2)+nao*(l0+0)+nao2, gout48*d_0+gout49*d_1+gout50*d_2+gout51*d_3+gout52*d_4+gout53*d_5);
            atomicAdd(vk+(i0+3)+nao*(l0+0)+nao2, gout54*d_0+gout55*d_1+gout56*d_2+gout57*d_3+gout58*d_4+gout59*d_5);
            atomicAdd(vk+(i0+4)+nao*(l0+0)+nao2, gout60*d_0+gout61*d_1+gout62*d_2+gout63*d_3+gout64*d_4+gout65*d_5);
            atomicAdd(vk+(i0+5)+nao*(l0+0)+nao2, gout66*d_0+gout67*d_1+gout68*d_2+gout69*d_3+gout70*d_4+gout71*d_5);
            atomicAdd(vk+(i0+0)+nao*(l0+0)+2*nao2, gout72*d_0+gout73*d_1+gout74*d_2+gout75*d_3+gout76*d_4+gout77*d_5);
            atomicAdd(vk+(i0+1)+nao*(l0+0)+2*nao2, gout78*d_0+gout79*d_1+gout80*d_2+gout81*d_3+gout82*d_4+gout83*d_5);
            atomicAdd(vk+(i0+2)+nao*(l0+0)+2*nao2, gout84*d_0+gout85*d_1+gout86*d_2+gout87*d_3+gout88*d_4+gout89*d_5);
            atomicAdd(vk+(i0+3)+nao*(l0+0)+2*nao2, gout90*d_0+gout91*d_1+gout92*d_2+gout93*d_3+gout94*d_4+gout95*d_5);
            atomicAdd(vk+(i0+4)+nao*(l0+0)+2*nao2, gout96*d_0+gout97*d_1+gout98*d_2+gout99*d_3+gout100*d_4+gout101*d_5);
            atomicAdd(vk+(i0+5)+nao*(l0+0)+2*nao2, gout102*d_0+gout103*d_1+gout104*d_2+gout105*d_3+gout106*d_4+gout107*d_5);
            // ijkl, jl -> ik
            d_0 = dm[(j0+0)+nao*(l0+0)];
            d_1 = dm[(j0+1)+nao*(l0+0)];
            d_2 = dm[(j0+2)+nao*(l0+0)];
            d_3 = dm[(j0+3)+nao*(l0+0)];
            d_4 = dm[(j0+4)+nao*(l0+0)];
            d_5 = dm[(j0+5)+nao*(l0+0)];
            atomicAdd(vk+(i0+0)+nao*(k0+0), gout0*d_0+gout1*d_1+gout2*d_2+gout3*d_3+gout4*d_4+gout5*d_5);
            atomicAdd(vk+(i0+1)+nao*(k0+0), gout6*d_0+gout7*d_1+gout8*d_2+gout9*d_3+gout10*d_4+gout11*d_5);
            atomicAdd(vk+(i0+2)+nao*(k0+0), gout12*d_0+gout13*d_1+gout14*d_2+gout15*d_3+gout16*d_4+gout17*d_5);
            atomicAdd(vk+(i0+3)+nao*(k0+0), gout18*d_0+gout19*d_1+gout20*d_2+gout21*d_3+gout22*d_4+gout23*d_5);
            atomicAdd(vk+(i0+4)+nao*(k0+0), gout24*d_0+gout25*d_1+gout26*d_2+gout27*d_3+gout28*d_4+gout29*d_5);
            atomicAdd(vk+(i0+5)+nao*(k0+0), gout30*d_0+gout31*d_1+gout32*d_2+gout33*d_3+gout34*d_4+gout35*d_5);
            atomicAdd(vk+(i0+0)+nao*(k0+0)+nao2, gout36*d_0+gout37*d_1+gout38*d_2+gout39*d_3+gout40*d_4+gout41*d_5);
            atomicAdd(vk+(i0+1)+nao*(k0+0)+nao2, gout42*d_0+gout43*d_1+gout44*d_2+gout45*d_3+gout46*d_4+gout47*d_5);
            atomicAdd(vk+(i0+2)+nao*(k0+0)+nao2, gout48*d_0+gout49*d_1+gout50*d_2+gout51*d_3+gout52*d_4+gout53*d_5);
            atomicAdd(vk+(i0+3)+nao*(k0+0)+nao2, gout54*d_0+gout55*d_1+gout56*d_2+gout57*d_3+gout58*d_4+gout59*d_5);
            atomicAdd(vk+(i0+4)+nao*(k0+0)+nao2, gout60*d_0+gout61*d_1+gout62*d_2+gout63*d_3+gout64*d_4+gout65*d_5);
            atomicAdd(vk+(i0+5)+nao*(k0+0)+nao2, gout66*d_0+gout67*d_1+gout68*d_2+gout69*d_3+gout70*d_4+gout71*d_5);
            atomicAdd(vk+(i0+0)+nao*(k0+0)+2*nao2, gout72*d_0+gout73*d_1+gout74*d_2+gout75*d_3+gout76*d_4+gout77*d_5);
            atomicAdd(vk+(i0+1)+nao*(k0+0)+2*nao2, gout78*d_0+gout79*d_1+gout80*d_2+gout81*d_3+gout82*d_4+gout83*d_5);
            atomicAdd(vk+(i0+2)+nao*(k0+0)+2*nao2, gout84*d_0+gout85*d_1+gout86*d_2+gout87*d_3+gout88*d_4+gout89*d_5);
            atomicAdd(vk+(i0+3)+nao*(k0+0)+2*nao2, gout90*d_0+gout91*d_1+gout92*d_2+gout93*d_3+gout94*d_4+gout95*d_5);
            atomicAdd(vk+(i0+4)+nao*(k0+0)+2*nao2, gout96*d_0+gout97*d_1+gout98*d_2+gout99*d_3+gout100*d_4+gout101*d_5);
            atomicAdd(vk+(i0+5)+nao*(k0+0)+2*nao2, gout102*d_0+gout103*d_1+gout104*d_2+gout105*d_3+gout106*d_4+gout107*d_5);
            // ijkl, ik -> jl
            d_0 = dm[(i0+0)+nao*(k0+0)];
            d_1 = dm[(i0+1)+nao*(k0+0)];
            d_2 = dm[(i0+2)+nao*(k0+0)];
            d_3 = dm[(i0+3)+nao*(k0+0)];
            d_4 = dm[(i0+4)+nao*(k0+0)];
            d_5 = dm[(i0+5)+nao*(k0+0)];
            atomicAdd(vk+(j0+0)+nao*(l0+0), gout108*d_0+gout114*d_1+gout120*d_2+gout126*d_3+gout132*d_4+gout138*d_5);
            atomicAdd(vk+(j0+1)+nao*(l0+0), gout109*d_0+gout115*d_1+gout121*d_2+gout127*d_3+gout133*d_4+gout139*d_5);
            atomicAdd(vk+(j0+2)+nao*(l0+0), gout110*d_0+gout116*d_1+gout122*d_2+gout128*d_3+gout134*d_4+gout140*d_5);
            atomicAdd(vk+(j0+3)+nao*(l0+0), gout111*d_0+gout117*d_1+gout123*d_2+gout129*d_3+gout135*d_4+gout141*d_5);
            atomicAdd(vk+(j0+4)+nao*(l0+0), gout112*d_0+gout118*d_1+gout124*d_2+gout130*d_3+gout136*d_4+gout142*d_5);
            atomicAdd(vk+(j0+5)+nao*(l0+0), gout113*d_0+gout119*d_1+gout125*d_2+gout131*d_3+gout137*d_4+gout143*d_5);
            atomicAdd(vk+(j0+0)+nao*(l0+0)+nao2, gout144*d_0+gout150*d_1+gout156*d_2+gout162*d_3+gout168*d_4+gout174*d_5);
            atomicAdd(vk+(j0+1)+nao*(l0+0)+nao2, gout145*d_0+gout151*d_1+gout157*d_2+gout163*d_3+gout169*d_4+gout175*d_5);
            atomicAdd(vk+(j0+2)+nao*(l0+0)+nao2, gout146*d_0+gout152*d_1+gout158*d_2+gout164*d_3+gout170*d_4+gout176*d_5);
            atomicAdd(vk+(j0+3)+nao*(l0+0)+nao2, gout147*d_0+gout153*d_1+gout159*d_2+gout165*d_3+gout171*d_4+gout177*d_5);
            atomicAdd(vk+(j0+4)+nao*(l0+0)+nao2, gout148*d_0+gout154*d_1+gout160*d_2+gout166*d_3+gout172*d_4+gout178*d_5);
            atomicAdd(vk+(j0+5)+nao*(l0+0)+nao2, gout149*d_0+gout155*d_1+gout161*d_2+gout167*d_3+gout173*d_4+gout179*d_5);
            atomicAdd(vk+(j0+0)+nao*(l0+0)+2*nao2, gout180*d_0+gout186*d_1+gout192*d_2+gout198*d_3+gout204*d_4+gout210*d_5);
            atomicAdd(vk+(j0+1)+nao*(l0+0)+2*nao2, gout181*d_0+gout187*d_1+gout193*d_2+gout199*d_3+gout205*d_4+gout211*d_5);
            atomicAdd(vk+(j0+2)+nao*(l0+0)+2*nao2, gout182*d_0+gout188*d_1+gout194*d_2+gout200*d_3+gout206*d_4+gout212*d_5);
            atomicAdd(vk+(j0+3)+nao*(l0+0)+2*nao2, gout183*d_0+gout189*d_1+gout195*d_2+gout201*d_3+gout207*d_4+gout213*d_5);
            atomicAdd(vk+(j0+4)+nao*(l0+0)+2*nao2, gout184*d_0+gout190*d_1+gout196*d_2+gout202*d_3+gout208*d_4+gout214*d_5);
            atomicAdd(vk+(j0+5)+nao*(l0+0)+2*nao2, gout185*d_0+gout191*d_1+gout197*d_2+gout203*d_3+gout209*d_4+gout215*d_5);
            // ijkl, il -> jk
            d_0 = dm[(i0+0)+nao*(l0+0)];
            d_1 = dm[(i0+1)+nao*(l0+0)];
            d_2 = dm[(i0+2)+nao*(l0+0)];
            d_3 = dm[(i0+3)+nao*(l0+0)];
            d_4 = dm[(i0+4)+nao*(l0+0)];
            d_5 = dm[(i0+5)+nao*(l0+0)];
            atomicAdd(vk+(j0+0)+nao*(k0+0), gout108*d_0+gout114*d_1+gout120*d_2+gout126*d_3+gout132*d_4+gout138*d_5);
            atomicAdd(vk+(j0+1)+nao*(k0+0), gout109*d_0+gout115*d_1+gout121*d_2+gout127*d_3+gout133*d_4+gout139*d_5);
            atomicAdd(vk+(j0+2)+nao*(k0+0), gout110*d_0+gout116*d_1+gout122*d_2+gout128*d_3+gout134*d_4+gout140*d_5);
            atomicAdd(vk+(j0+3)+nao*(k0+0), gout111*d_0+gout117*d_1+gout123*d_2+gout129*d_3+gout135*d_4+gout141*d_5);
            atomicAdd(vk+(j0+4)+nao*(k0+0), gout112*d_0+gout118*d_1+gout124*d_2+gout130*d_3+gout136*d_4+gout142*d_5);
            atomicAdd(vk+(j0+5)+nao*(k0+0), gout113*d_0+gout119*d_1+gout125*d_2+gout131*d_3+gout137*d_4+gout143*d_5);
            atomicAdd(vk+(j0+0)+nao*(k0+0)+nao2, gout144*d_0+gout150*d_1+gout156*d_2+gout162*d_3+gout168*d_4+gout174*d_5);
            atomicAdd(vk+(j0+1)+nao*(k0+0)+nao2, gout145*d_0+gout151*d_1+gout157*d_2+gout163*d_3+gout169*d_4+gout175*d_5);
            atomicAdd(vk+(j0+2)+nao*(k0+0)+nao2, gout146*d_0+gout152*d_1+gout158*d_2+gout164*d_3+gout170*d_4+gout176*d_5);
            atomicAdd(vk+(j0+3)+nao*(k0+0)+nao2, gout147*d_0+gout153*d_1+gout159*d_2+gout165*d_3+gout171*d_4+gout177*d_5);
            atomicAdd(vk+(j0+4)+nao*(k0+0)+nao2, gout148*d_0+gout154*d_1+gout160*d_2+gout166*d_3+gout172*d_4+gout178*d_5);
            atomicAdd(vk+(j0+5)+nao*(k0+0)+nao2, gout149*d_0+gout155*d_1+gout161*d_2+gout167*d_3+gout173*d_4+gout179*d_5);
            atomicAdd(vk+(j0+0)+nao*(k0+0)+2*nao2, gout180*d_0+gout186*d_1+gout192*d_2+gout198*d_3+gout204*d_4+gout210*d_5);
            atomicAdd(vk+(j0+1)+nao*(k0+0)+2*nao2, gout181*d_0+gout187*d_1+gout193*d_2+gout199*d_3+gout205*d_4+gout211*d_5);
            atomicAdd(vk+(j0+2)+nao*(k0+0)+2*nao2, gout182*d_0+gout188*d_1+gout194*d_2+gout200*d_3+gout206*d_4+gout212*d_5);
            atomicAdd(vk+(j0+3)+nao*(k0+0)+2*nao2, gout183*d_0+gout189*d_1+gout195*d_2+gout201*d_3+gout207*d_4+gout213*d_5);
            atomicAdd(vk+(j0+4)+nao*(k0+0)+2*nao2, gout184*d_0+gout190*d_1+gout196*d_2+gout202*d_3+gout208*d_4+gout214*d_5);
            atomicAdd(vk+(j0+5)+nao*(k0+0)+2*nao2, gout185*d_0+gout191*d_1+gout197*d_2+gout203*d_3+gout209*d_4+gout215*d_5);
            vk += 3*nao2;
        }
        dm += nao2;
    }
}

__global__
static void GINTint2e_ip1_jk_kernel_3000(GINTEnvVars envs, JKMatrix jk,
                                    BasisProdOffsets offsets)
{
    int ntasks_ij = offsets.ntasks_ij;
    int ntasks_kl = offsets.ntasks_kl;
    int task_ij = blockIdx.x * blockDim.x + threadIdx.x;
    int task_kl = blockIdx.y * blockDim.y + threadIdx.y;
    if (task_ij >= ntasks_ij || task_kl >= ntasks_kl) {
        return;
    }
    int bas_ij = offsets.bas_ij + task_ij;
    int bas_kl = offsets.bas_kl + task_kl;
    double norm = envs.fac;
    double omega = envs.omega;
    int *bas_pair2bra = c_bpcache.bas_pair2bra;
    int *bas_pair2ket = c_bpcache.bas_pair2ket;
    int ish = bas_pair2bra[bas_ij];
    int jsh = bas_pair2ket[bas_ij];
    int ksh = bas_pair2bra[bas_kl];
    int lsh = bas_pair2ket[bas_kl];
    int nprim_ij = envs.nprim_ij;
    int nprim_kl = envs.nprim_kl;
    int prim_ij = offsets.primitive_ij + task_ij * nprim_ij;
    int prim_kl = offsets.primitive_kl + task_kl * nprim_kl;

    double* __restrict__ a12 = c_bpcache.a12;
    double* __restrict__ e12 = c_bpcache.e12;
    double* __restrict__ x12 = c_bpcache.x12;
    double* __restrict__ y12 = c_bpcache.y12;
    double* __restrict__ z12 = c_bpcache.z12;
    double * __restrict__ i_exponent = c_bpcache.a1;
    double * __restrict__ j_exponent = c_bpcache.a2;

    int ij, kl;
    int prim_ij0, prim_ij1, prim_kl0, prim_kl1;
    int nbas = c_bpcache.nbas;
    double* __restrict__ bas_x = c_bpcache.bas_coords;
    double* __restrict__ bas_y = bas_x + nbas;
    double* __restrict__ bas_z = bas_y + nbas;

    double gout0 = 0;
    double gout1 = 0;
    double gout2 = 0;
    double gout3 = 0;
    double gout4 = 0;
    double gout5 = 0;
    double gout6 = 0;
    double gout7 = 0;
    double gout8 = 0;
    double gout9 = 0;
    double gout10 = 0;
    double gout11 = 0;
    double gout12 = 0;
    double gout13 = 0;
    double gout14 = 0;
    double gout15 = 0;
    double gout16 = 0;
    double gout17 = 0;
    double gout18 = 0;
    double gout19 = 0;
    double gout20 = 0;
    double gout21 = 0;
    double gout22 = 0;
    double gout23 = 0;
    double gout24 = 0;
    double gout25 = 0;
    double gout26 = 0;
    double gout27 = 0;
    double gout28 = 0;
    double gout29 = 0;
    double gout30 = 0;
    double gout31 = 0;
    double gout32 = 0;
    double gout33 = 0;
    double gout34 = 0;
    double gout35 = 0;
    double gout36 = 0;
    double gout37 = 0;
    double gout38 = 0;
    double gout39 = 0;
    double gout40 = 0;
    double gout41 = 0;
    double gout42 = 0;
    double gout43 = 0;
    double gout44 = 0;
    double gout45 = 0;
    double gout46 = 0;
    double gout47 = 0;
    double gout48 = 0;
    double gout49 = 0;
    double gout50 = 0;
    double gout51 = 0;
    double gout52 = 0;
    double gout53 = 0;
    double gout54 = 0;
    double gout55 = 0;
    double gout56 = 0;
    double gout57 = 0;
    double gout58 = 0;
    double gout59 = 0;

    double xi = bas_x[ish];
    double yi = bas_y[ish];
    double zi = bas_z[ish];
    double ABx = xi - bas_x[jsh];
    double ABy = yi - bas_y[jsh];
    double ABz = zi - bas_z[jsh];


    prim_ij0 = prim_ij;
    prim_ij1 = prim_ij + nprim_ij;
    prim_kl0 = prim_kl;
    prim_kl1 = prim_kl + nprim_kl;
    double rw[6];
    int irys;
    for (ij = prim_ij0; ij < prim_ij1; ++ij) {
        double alpha = i_exponent[ij];
        double beta = j_exponent[ij];
        double aij = a12[ij];
        double eij = e12[ij];
        double xij = x12[ij];
        double yij = y12[ij];
        double zij = z12[ij];
    for (kl = prim_kl0; kl < prim_kl1; ++kl) {
        double akl = a12[kl];
        double ekl = e12[kl];
        double xkl = x12[kl];
        double ykl = y12[kl];
        double zkl = z12[kl];
        double xijxkl = xij - xkl;
        double yijykl = yij - ykl;
        double zijzkl = zij - zkl;
        double aijkl = aij + akl;
        double a1 = aij * akl;
        double a0 = a1 / aijkl;
        double theta = omega > 0.0 ? omega * omega / (omega * omega + a0) : 1.0; 
        a0 *= theta;
        double x = a0 * (xijxkl * xijxkl + yijykl * yijykl + zijzkl * zijzkl);
        double fac = norm * eij * ekl * sqrt(a0 / (a1 * a1 * a1));
        //double fac = norm * eij * ekl / (sqrt(aijkl) * a1);

        GINTrys_root<3>(x, rw);
        GINTscale_u<3>(rw, theta);
      for (irys = 0; irys < 3; ++irys) {
            double weight0 = rw[irys+3] * fac;
            double root0 = rw[irys];
            double u2 = a0 * root0;
            double tmp4 = .5 / (u2 * aijkl + a1);
            double B00 = u2 * tmp4;
            double tmp1 = 2 * B00;
            double B10 = B00 + tmp4 * akl;
            double tmp2 = tmp1 * akl;
            double C00x = xij - xi - tmp2 * xijxkl;
            double C00y = yij - yi - tmp2 * yijykl;
            double C00z = zij - zi - tmp2 * zijzkl;



            double g0 = B10+C00x*C00x;
            double g1 = 3*B10*C00x;
            double g2 = g1+C00x*C00x*C00x;
            double g3 = 3*B10*B10;
            double g4 = 6*B10*C00x*C00x;
            double g5 = g3+g4+C00x*C00x*C00x*C00x;
            double g6 = ABx+C00x;
            double g8 = B10+(C00x*g6);
            double g10 = g1+C00x*C00x*C00x+(ABx*g0);
            double g15 = g3+(C00x*C00x*C00x*g6)+(3*B10*C00x*(ABx+(2*C00x)));
            double g16 = B10+C00y*C00y;
            double g17 = 3*B10*C00y;
            double g18 = g17+C00y*C00y*C00y;
            double g20 = g3+(6*B10*C00y*C00y)+C00y*C00y*C00y*C00y;
            double g21 = ABy+C00y;
            double g23 = B10+(C00y*g21);
            double g25 = g17+C00y*C00y*C00y+(ABy*g16);
            double g30 = g3+(C00y*C00y*C00y*g21)+(3*B10*C00y*(ABy+(2*C00y)));
            double g31 = B10+C00z*C00z;
            double g32 = 3*B10*C00z;
            double g33 = g32+C00z*C00z*C00z;
            double g35 = g3+(6*B10*C00z*C00z)+C00z*C00z*C00z*C00z;
            double g36 = ABz+C00z;
            double g38 = B10+(C00z*g36);
            double g40 = g32+C00z*C00z*C00z+(ABz*g31);
            double g45 = g3+(C00z*C00z*C00z*g36)+(3*B10*C00z*(ABz+(2*C00z)));

            gout0 += (-3*g0 + 2*alpha*g5) * weight0;
            gout1 += (-2*C00x + 2*alpha*g2) * (C00y) * weight0;
            gout2 += (-2*C00x + 2*alpha*g2) * (C00z) * weight0;
            gout3 += (-1 + 2*alpha*g0) * (g16) * weight0;
            gout4 += (-1 + 2*alpha*g0) * (C00y) * (C00z) * weight0;
            gout5 += (-1 + 2*alpha*g0) * (g31) * weight0;
            gout6 += (2*alpha*C00x) * (g18) * weight0;
            gout7 += (2*alpha*C00x) * (g16) * (C00z) * weight0;
            gout8 += (2*alpha*C00x) * (C00y) * (g31) * weight0;
            gout9 += (2*alpha*C00x) * (g33) * weight0;
            gout10 += (g2) * (2*alpha*C00y) * weight0;
            gout11 += (g0) * (-1 + 2*alpha*g16) * weight0;
            gout12 += (g0) * (2*alpha*C00y) * (C00z) * weight0;
            gout13 += (C00x) * (-2*C00y + 2*alpha*g18) * weight0;
            gout14 += (C00x) * (-1 + 2*alpha*g16) * (C00z) * weight0;
            gout15 += (C00x) * (2*alpha*C00y) * (g31) * weight0;
            gout16 += (-3*g16 + 2*alpha*g20) * weight0;
            gout17 += (-2*C00y + 2*alpha*g18) * (C00z) * weight0;
            gout18 += (-1 + 2*alpha*g16) * (g31) * weight0;
            gout19 += (2*alpha*C00y) * (g33) * weight0;
            gout20 += (g2) * (2*alpha*C00z) * weight0;
            gout21 += (g0) * (C00y) * (2*alpha*C00z) * weight0;
            gout22 += (g0) * (-1 + 2*alpha*g31) * weight0;
            gout23 += (C00x) * (g16) * (2*alpha*C00z) * weight0;
            gout24 += (C00x) * (C00y) * (-1 + 2*alpha*g31) * weight0;
            gout25 += (C00x) * (-2*C00z + 2*alpha*g33) * weight0;
            gout26 += (g18) * (2*alpha*C00z) * weight0;
            gout27 += (g16) * (-1 + 2*alpha*g31) * weight0;
            gout28 += (C00y) * (-2*C00z + 2*alpha*g33) * weight0;
            gout29 += (-3*g31 + 2*alpha*g35) * weight0;
            gout30 += (2*beta*g15) * weight0;
            gout31 += (2*beta*g10) * (C00y) * weight0;
            gout32 += (2*beta*g10) * (C00z) * weight0;
            gout33 += (2*beta*g8) * (g16) * weight0;
            gout34 += (2*beta*g8) * (C00y) * (C00z) * weight0;
            gout35 += (2*beta*g8) * (g31) * weight0;
            gout36 += (2*beta*g6) * (g18) * weight0;
            gout37 += (2*beta*g6) * (g16) * (C00z) * weight0;
            gout38 += (2*beta*g6) * (C00y) * (g31) * weight0;
            gout39 += (2*beta*g6) * (g33) * weight0;
            gout40 += (g2) * (2*beta*g21) * weight0;
            gout41 += (g0) * (2*beta*g23) * weight0;
            gout42 += (g0) * (2*beta*g21) * (C00z) * weight0;
            gout43 += (C00x) * (2*beta*g25) * weight0;
            gout44 += (C00x) * (2*beta*g23) * (C00z) * weight0;
            gout45 += (C00x) * (2*beta*g21) * (g31) * weight0;
            gout46 += (2*beta*g30) * weight0;
            gout47 += (2*beta*g25) * (C00z) * weight0;
            gout48 += (2*beta*g23) * (g31) * weight0;
            gout49 += (2*beta*g21) * (g33) * weight0;
            gout50 += (g2) * (2*beta*g36) * weight0;
            gout51 += (g0) * (C00y) * (2*beta*g36) * weight0;
            gout52 += (g0) * (2*beta*g38) * weight0;
            gout53 += (C00x) * (g16) * (2*beta*g36) * weight0;
            gout54 += (C00x) * (C00y) * (2*beta*g38) * weight0;
            gout55 += (C00x) * (2*beta*g40) * weight0;
            gout56 += (g18) * (2*beta*g36) * weight0;
            gout57 += (g16) * (2*beta*g38) * weight0;
            gout58 += (C00y) * (2*beta*g40) * weight0;
            gout59 += (2*beta*g45) * weight0;
        }
    } }

    int *ao_loc = c_bpcache.ao_loc;
    int i0 = ao_loc[ish];
    int j0 = ao_loc[jsh];
    int k0 = ao_loc[ksh];
    int l0 = ao_loc[lsh];
    int n_dm = jk.n_dm;
    int nao = jk.nao;
    size_t nao2 = nao * nao;
    double* __restrict__ dm = jk.dm;
    double *vj = jk.vj;
    double *vk = jk.vk;
    double d_0, d_1, d_2, d_3, d_4, d_5, d_6, d_7, d_8, d_9;

    for (int i_dm = 0; i_dm < n_dm; ++i_dm) {
        if (vj != NULL) {
            d_0 = dm[(k0+0)+nao*(l0+0)];
            atomicAdd(vj+(i0+0)+nao*(j0+0), gout0*d_0);
            atomicAdd(vj+(i0+1)+nao*(j0+0), gout1*d_0);
            atomicAdd(vj+(i0+2)+nao*(j0+0), gout2*d_0);
            atomicAdd(vj+(i0+3)+nao*(j0+0), gout3*d_0);
            atomicAdd(vj+(i0+4)+nao*(j0+0), gout4*d_0);
            atomicAdd(vj+(i0+5)+nao*(j0+0), gout5*d_0);
            atomicAdd(vj+(i0+6)+nao*(j0+0), gout6*d_0);
            atomicAdd(vj+(i0+7)+nao*(j0+0), gout7*d_0);
            atomicAdd(vj+(i0+8)+nao*(j0+0), gout8*d_0);
            atomicAdd(vj+(i0+9)+nao*(j0+0), gout9*d_0);
            atomicAdd(vj+(i0+0)+nao*(j0+0)+nao2, gout10*d_0);
            atomicAdd(vj+(i0+1)+nao*(j0+0)+nao2, gout11*d_0);
            atomicAdd(vj+(i0+2)+nao*(j0+0)+nao2, gout12*d_0);
            atomicAdd(vj+(i0+3)+nao*(j0+0)+nao2, gout13*d_0);
            atomicAdd(vj+(i0+4)+nao*(j0+0)+nao2, gout14*d_0);
            atomicAdd(vj+(i0+5)+nao*(j0+0)+nao2, gout15*d_0);
            atomicAdd(vj+(i0+6)+nao*(j0+0)+nao2, gout16*d_0);
            atomicAdd(vj+(i0+7)+nao*(j0+0)+nao2, gout17*d_0);
            atomicAdd(vj+(i0+8)+nao*(j0+0)+nao2, gout18*d_0);
            atomicAdd(vj+(i0+9)+nao*(j0+0)+nao2, gout19*d_0);
            atomicAdd(vj+(i0+0)+nao*(j0+0)+2*nao2, gout20*d_0);
            atomicAdd(vj+(i0+1)+nao*(j0+0)+2*nao2, gout21*d_0);
            atomicAdd(vj+(i0+2)+nao*(j0+0)+2*nao2, gout22*d_0);
            atomicAdd(vj+(i0+3)+nao*(j0+0)+2*nao2, gout23*d_0);
            atomicAdd(vj+(i0+4)+nao*(j0+0)+2*nao2, gout24*d_0);
            atomicAdd(vj+(i0+5)+nao*(j0+0)+2*nao2, gout25*d_0);
            atomicAdd(vj+(i0+6)+nao*(j0+0)+2*nao2, gout26*d_0);
            atomicAdd(vj+(i0+7)+nao*(j0+0)+2*nao2, gout27*d_0);
            atomicAdd(vj+(i0+8)+nao*(j0+0)+2*nao2, gout28*d_0);
            atomicAdd(vj+(i0+9)+nao*(j0+0)+2*nao2, gout29*d_0);
            atomicAdd(vj+nao*(i0+0)+(j0+0), gout30*d_0);
            atomicAdd(vj+nao*(i0+1)+(j0+0), gout31*d_0);
            atomicAdd(vj+nao*(i0+2)+(j0+0), gout32*d_0);
            atomicAdd(vj+nao*(i0+3)+(j0+0), gout33*d_0);
            atomicAdd(vj+nao*(i0+4)+(j0+0), gout34*d_0);
            atomicAdd(vj+nao*(i0+5)+(j0+0), gout35*d_0);
            atomicAdd(vj+nao*(i0+6)+(j0+0), gout36*d_0);
            atomicAdd(vj+nao*(i0+7)+(j0+0), gout37*d_0);
            atomicAdd(vj+nao*(i0+8)+(j0+0), gout38*d_0);
            atomicAdd(vj+nao*(i0+9)+(j0+0), gout39*d_0);
            atomicAdd(vj+nao*(i0+0)+(j0+0)+nao2, gout40*d_0);
            atomicAdd(vj+nao*(i0+1)+(j0+0)+nao2, gout41*d_0);
            atomicAdd(vj+nao*(i0+2)+(j0+0)+nao2, gout42*d_0);
            atomicAdd(vj+nao*(i0+3)+(j0+0)+nao2, gout43*d_0);
            atomicAdd(vj+nao*(i0+4)+(j0+0)+nao2, gout44*d_0);
            atomicAdd(vj+nao*(i0+5)+(j0+0)+nao2, gout45*d_0);
            atomicAdd(vj+nao*(i0+6)+(j0+0)+nao2, gout46*d_0);
            atomicAdd(vj+nao*(i0+7)+(j0+0)+nao2, gout47*d_0);
            atomicAdd(vj+nao*(i0+8)+(j0+0)+nao2, gout48*d_0);
            atomicAdd(vj+nao*(i0+9)+(j0+0)+nao2, gout49*d_0);
            atomicAdd(vj+nao*(i0+0)+(j0+0)+2*nao2, gout50*d_0);
            atomicAdd(vj+nao*(i0+1)+(j0+0)+2*nao2, gout51*d_0);
            atomicAdd(vj+nao*(i0+2)+(j0+0)+2*nao2, gout52*d_0);
            atomicAdd(vj+nao*(i0+3)+(j0+0)+2*nao2, gout53*d_0);
            atomicAdd(vj+nao*(i0+4)+(j0+0)+2*nao2, gout54*d_0);
            atomicAdd(vj+nao*(i0+5)+(j0+0)+2*nao2, gout55*d_0);
            atomicAdd(vj+nao*(i0+6)+(j0+0)+2*nao2, gout56*d_0);
            atomicAdd(vj+nao*(i0+7)+(j0+0)+2*nao2, gout57*d_0);
            atomicAdd(vj+nao*(i0+8)+(j0+0)+2*nao2, gout58*d_0);
            atomicAdd(vj+nao*(i0+9)+(j0+0)+2*nao2, gout59*d_0);
            vj += 3*nao2;
        }
        if (vk != NULL) {
            // ijkl, jk -> il
            d_0 = dm[(j0+0)+nao*(k0+0)];
            atomicAdd(vk+(i0+0)+nao*(l0+0), gout0*d_0);
            atomicAdd(vk+(i0+1)+nao*(l0+0), gout1*d_0);
            atomicAdd(vk+(i0+2)+nao*(l0+0), gout2*d_0);
            atomicAdd(vk+(i0+3)+nao*(l0+0), gout3*d_0);
            atomicAdd(vk+(i0+4)+nao*(l0+0), gout4*d_0);
            atomicAdd(vk+(i0+5)+nao*(l0+0), gout5*d_0);
            atomicAdd(vk+(i0+6)+nao*(l0+0), gout6*d_0);
            atomicAdd(vk+(i0+7)+nao*(l0+0), gout7*d_0);
            atomicAdd(vk+(i0+8)+nao*(l0+0), gout8*d_0);
            atomicAdd(vk+(i0+9)+nao*(l0+0), gout9*d_0);
            atomicAdd(vk+(i0+0)+nao*(l0+0)+nao2, gout10*d_0);
            atomicAdd(vk+(i0+1)+nao*(l0+0)+nao2, gout11*d_0);
            atomicAdd(vk+(i0+2)+nao*(l0+0)+nao2, gout12*d_0);
            atomicAdd(vk+(i0+3)+nao*(l0+0)+nao2, gout13*d_0);
            atomicAdd(vk+(i0+4)+nao*(l0+0)+nao2, gout14*d_0);
            atomicAdd(vk+(i0+5)+nao*(l0+0)+nao2, gout15*d_0);
            atomicAdd(vk+(i0+6)+nao*(l0+0)+nao2, gout16*d_0);
            atomicAdd(vk+(i0+7)+nao*(l0+0)+nao2, gout17*d_0);
            atomicAdd(vk+(i0+8)+nao*(l0+0)+nao2, gout18*d_0);
            atomicAdd(vk+(i0+9)+nao*(l0+0)+nao2, gout19*d_0);
            atomicAdd(vk+(i0+0)+nao*(l0+0)+2*nao2, gout20*d_0);
            atomicAdd(vk+(i0+1)+nao*(l0+0)+2*nao2, gout21*d_0);
            atomicAdd(vk+(i0+2)+nao*(l0+0)+2*nao2, gout22*d_0);
            atomicAdd(vk+(i0+3)+nao*(l0+0)+2*nao2, gout23*d_0);
            atomicAdd(vk+(i0+4)+nao*(l0+0)+2*nao2, gout24*d_0);
            atomicAdd(vk+(i0+5)+nao*(l0+0)+2*nao2, gout25*d_0);
            atomicAdd(vk+(i0+6)+nao*(l0+0)+2*nao2, gout26*d_0);
            atomicAdd(vk+(i0+7)+nao*(l0+0)+2*nao2, gout27*d_0);
            atomicAdd(vk+(i0+8)+nao*(l0+0)+2*nao2, gout28*d_0);
            atomicAdd(vk+(i0+9)+nao*(l0+0)+2*nao2, gout29*d_0);
            // ijkl, jl -> ik
            d_0 = dm[(j0+0)+nao*(l0+0)];
            atomicAdd(vk+(i0+0)+nao*(k0+0), gout0*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+0), gout1*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+0), gout2*d_0);
            atomicAdd(vk+(i0+3)+nao*(k0+0), gout3*d_0);
            atomicAdd(vk+(i0+4)+nao*(k0+0), gout4*d_0);
            atomicAdd(vk+(i0+5)+nao*(k0+0), gout5*d_0);
            atomicAdd(vk+(i0+6)+nao*(k0+0), gout6*d_0);
            atomicAdd(vk+(i0+7)+nao*(k0+0), gout7*d_0);
            atomicAdd(vk+(i0+8)+nao*(k0+0), gout8*d_0);
            atomicAdd(vk+(i0+9)+nao*(k0+0), gout9*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+0)+nao2, gout10*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+0)+nao2, gout11*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+0)+nao2, gout12*d_0);
            atomicAdd(vk+(i0+3)+nao*(k0+0)+nao2, gout13*d_0);
            atomicAdd(vk+(i0+4)+nao*(k0+0)+nao2, gout14*d_0);
            atomicAdd(vk+(i0+5)+nao*(k0+0)+nao2, gout15*d_0);
            atomicAdd(vk+(i0+6)+nao*(k0+0)+nao2, gout16*d_0);
            atomicAdd(vk+(i0+7)+nao*(k0+0)+nao2, gout17*d_0);
            atomicAdd(vk+(i0+8)+nao*(k0+0)+nao2, gout18*d_0);
            atomicAdd(vk+(i0+9)+nao*(k0+0)+nao2, gout19*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+0)+2*nao2, gout20*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+0)+2*nao2, gout21*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+0)+2*nao2, gout22*d_0);
            atomicAdd(vk+(i0+3)+nao*(k0+0)+2*nao2, gout23*d_0);
            atomicAdd(vk+(i0+4)+nao*(k0+0)+2*nao2, gout24*d_0);
            atomicAdd(vk+(i0+5)+nao*(k0+0)+2*nao2, gout25*d_0);
            atomicAdd(vk+(i0+6)+nao*(k0+0)+2*nao2, gout26*d_0);
            atomicAdd(vk+(i0+7)+nao*(k0+0)+2*nao2, gout27*d_0);
            atomicAdd(vk+(i0+8)+nao*(k0+0)+2*nao2, gout28*d_0);
            atomicAdd(vk+(i0+9)+nao*(k0+0)+2*nao2, gout29*d_0);
            // ijkl, ik -> jl
            d_0 = dm[(i0+0)+nao*(k0+0)];
            d_1 = dm[(i0+1)+nao*(k0+0)];
            d_2 = dm[(i0+2)+nao*(k0+0)];
            d_3 = dm[(i0+3)+nao*(k0+0)];
            d_4 = dm[(i0+4)+nao*(k0+0)];
            d_5 = dm[(i0+5)+nao*(k0+0)];
            d_6 = dm[(i0+6)+nao*(k0+0)];
            d_7 = dm[(i0+7)+nao*(k0+0)];
            d_8 = dm[(i0+8)+nao*(k0+0)];
            d_9 = dm[(i0+9)+nao*(k0+0)];
            atomicAdd(vk+(j0+0)+nao*(l0+0), gout30*d_0+gout31*d_1+gout32*d_2+gout33*d_3+gout34*d_4+gout35*d_5+gout36*d_6+gout37*d_7+gout38*d_8+gout39*d_9);
            atomicAdd(vk+(j0+0)+nao*(l0+0)+nao2, gout40*d_0+gout41*d_1+gout42*d_2+gout43*d_3+gout44*d_4+gout45*d_5+gout46*d_6+gout47*d_7+gout48*d_8+gout49*d_9);
            atomicAdd(vk+(j0+0)+nao*(l0+0)+2*nao2, gout50*d_0+gout51*d_1+gout52*d_2+gout53*d_3+gout54*d_4+gout55*d_5+gout56*d_6+gout57*d_7+gout58*d_8+gout59*d_9);
            // ijkl, il -> jk
            d_0 = dm[(i0+0)+nao*(l0+0)];
            d_1 = dm[(i0+1)+nao*(l0+0)];
            d_2 = dm[(i0+2)+nao*(l0+0)];
            d_3 = dm[(i0+3)+nao*(l0+0)];
            d_4 = dm[(i0+4)+nao*(l0+0)];
            d_5 = dm[(i0+5)+nao*(l0+0)];
            d_6 = dm[(i0+6)+nao*(l0+0)];
            d_7 = dm[(i0+7)+nao*(l0+0)];
            d_8 = dm[(i0+8)+nao*(l0+0)];
            d_9 = dm[(i0+9)+nao*(l0+0)];
            atomicAdd(vk+(j0+0)+nao*(k0+0), gout30*d_0+gout31*d_1+gout32*d_2+gout33*d_3+gout34*d_4+gout35*d_5+gout36*d_6+gout37*d_7+gout38*d_8+gout39*d_9);
            atomicAdd(vk+(j0+0)+nao*(k0+0)+nao2, gout40*d_0+gout41*d_1+gout42*d_2+gout43*d_3+gout44*d_4+gout45*d_5+gout46*d_6+gout47*d_7+gout48*d_8+gout49*d_9);
            atomicAdd(vk+(j0+0)+nao*(k0+0)+2*nao2, gout50*d_0+gout51*d_1+gout52*d_2+gout53*d_3+gout54*d_4+gout55*d_5+gout56*d_6+gout57*d_7+gout58*d_8+gout59*d_9);
            vk += 3*nao2;
        }
        dm += nao2;
    }
}

__global__
static void GINTint2e_ip1_jk_kernel_3010(GINTEnvVars envs, JKMatrix jk,
                                    BasisProdOffsets offsets)
{
    int ntasks_ij = offsets.ntasks_ij;
    int ntasks_kl = offsets.ntasks_kl;
    int task_ij = blockIdx.x * blockDim.x + threadIdx.x;
    int task_kl = blockIdx.y * blockDim.y + threadIdx.y;
    if (task_ij >= ntasks_ij || task_kl >= ntasks_kl) {
        return;
    }
    int bas_ij = offsets.bas_ij + task_ij;
    int bas_kl = offsets.bas_kl + task_kl;
    double norm = envs.fac;
    double omega = envs.omega;
    int *bas_pair2bra = c_bpcache.bas_pair2bra;
    int *bas_pair2ket = c_bpcache.bas_pair2ket;
    int ish = bas_pair2bra[bas_ij];
    int jsh = bas_pair2ket[bas_ij];
    int ksh = bas_pair2bra[bas_kl];
    int lsh = bas_pair2ket[bas_kl];
    int nprim_ij = envs.nprim_ij;
    int nprim_kl = envs.nprim_kl;
    int prim_ij = offsets.primitive_ij + task_ij * nprim_ij;
    int prim_kl = offsets.primitive_kl + task_kl * nprim_kl;

    double* __restrict__ a12 = c_bpcache.a12;
    double* __restrict__ e12 = c_bpcache.e12;
    double* __restrict__ x12 = c_bpcache.x12;
    double* __restrict__ y12 = c_bpcache.y12;
    double* __restrict__ z12 = c_bpcache.z12;
    double * __restrict__ i_exponent = c_bpcache.a1;
    double * __restrict__ j_exponent = c_bpcache.a2;

    int ij, kl;
    int prim_ij0, prim_ij1, prim_kl0, prim_kl1;
    int nbas = c_bpcache.nbas;
    double* __restrict__ bas_x = c_bpcache.bas_coords;
    double* __restrict__ bas_y = bas_x + nbas;
    double* __restrict__ bas_z = bas_y + nbas;

    double gout0 = 0;
    double gout1 = 0;
    double gout2 = 0;
    double gout3 = 0;
    double gout4 = 0;
    double gout5 = 0;
    double gout6 = 0;
    double gout7 = 0;
    double gout8 = 0;
    double gout9 = 0;
    double gout10 = 0;
    double gout11 = 0;
    double gout12 = 0;
    double gout13 = 0;
    double gout14 = 0;
    double gout15 = 0;
    double gout16 = 0;
    double gout17 = 0;
    double gout18 = 0;
    double gout19 = 0;
    double gout20 = 0;
    double gout21 = 0;
    double gout22 = 0;
    double gout23 = 0;
    double gout24 = 0;
    double gout25 = 0;
    double gout26 = 0;
    double gout27 = 0;
    double gout28 = 0;
    double gout29 = 0;
    double gout30 = 0;
    double gout31 = 0;
    double gout32 = 0;
    double gout33 = 0;
    double gout34 = 0;
    double gout35 = 0;
    double gout36 = 0;
    double gout37 = 0;
    double gout38 = 0;
    double gout39 = 0;
    double gout40 = 0;
    double gout41 = 0;
    double gout42 = 0;
    double gout43 = 0;
    double gout44 = 0;
    double gout45 = 0;
    double gout46 = 0;
    double gout47 = 0;
    double gout48 = 0;
    double gout49 = 0;
    double gout50 = 0;
    double gout51 = 0;
    double gout52 = 0;
    double gout53 = 0;
    double gout54 = 0;
    double gout55 = 0;
    double gout56 = 0;
    double gout57 = 0;
    double gout58 = 0;
    double gout59 = 0;
    double gout60 = 0;
    double gout61 = 0;
    double gout62 = 0;
    double gout63 = 0;
    double gout64 = 0;
    double gout65 = 0;
    double gout66 = 0;
    double gout67 = 0;
    double gout68 = 0;
    double gout69 = 0;
    double gout70 = 0;
    double gout71 = 0;
    double gout72 = 0;
    double gout73 = 0;
    double gout74 = 0;
    double gout75 = 0;
    double gout76 = 0;
    double gout77 = 0;
    double gout78 = 0;
    double gout79 = 0;
    double gout80 = 0;
    double gout81 = 0;
    double gout82 = 0;
    double gout83 = 0;
    double gout84 = 0;
    double gout85 = 0;
    double gout86 = 0;
    double gout87 = 0;
    double gout88 = 0;
    double gout89 = 0;
    double gout90 = 0;
    double gout91 = 0;
    double gout92 = 0;
    double gout93 = 0;
    double gout94 = 0;
    double gout95 = 0;
    double gout96 = 0;
    double gout97 = 0;
    double gout98 = 0;
    double gout99 = 0;
    double gout100 = 0;
    double gout101 = 0;
    double gout102 = 0;
    double gout103 = 0;
    double gout104 = 0;
    double gout105 = 0;
    double gout106 = 0;
    double gout107 = 0;
    double gout108 = 0;
    double gout109 = 0;
    double gout110 = 0;
    double gout111 = 0;
    double gout112 = 0;
    double gout113 = 0;
    double gout114 = 0;
    double gout115 = 0;
    double gout116 = 0;
    double gout117 = 0;
    double gout118 = 0;
    double gout119 = 0;
    double gout120 = 0;
    double gout121 = 0;
    double gout122 = 0;
    double gout123 = 0;
    double gout124 = 0;
    double gout125 = 0;
    double gout126 = 0;
    double gout127 = 0;
    double gout128 = 0;
    double gout129 = 0;
    double gout130 = 0;
    double gout131 = 0;
    double gout132 = 0;
    double gout133 = 0;
    double gout134 = 0;
    double gout135 = 0;
    double gout136 = 0;
    double gout137 = 0;
    double gout138 = 0;
    double gout139 = 0;
    double gout140 = 0;
    double gout141 = 0;
    double gout142 = 0;
    double gout143 = 0;
    double gout144 = 0;
    double gout145 = 0;
    double gout146 = 0;
    double gout147 = 0;
    double gout148 = 0;
    double gout149 = 0;
    double gout150 = 0;
    double gout151 = 0;
    double gout152 = 0;
    double gout153 = 0;
    double gout154 = 0;
    double gout155 = 0;
    double gout156 = 0;
    double gout157 = 0;
    double gout158 = 0;
    double gout159 = 0;
    double gout160 = 0;
    double gout161 = 0;
    double gout162 = 0;
    double gout163 = 0;
    double gout164 = 0;
    double gout165 = 0;
    double gout166 = 0;
    double gout167 = 0;
    double gout168 = 0;
    double gout169 = 0;
    double gout170 = 0;
    double gout171 = 0;
    double gout172 = 0;
    double gout173 = 0;
    double gout174 = 0;
    double gout175 = 0;
    double gout176 = 0;
    double gout177 = 0;
    double gout178 = 0;
    double gout179 = 0;

    double xi = bas_x[ish];
    double yi = bas_y[ish];
    double zi = bas_z[ish];
    double ABx = xi - bas_x[jsh];
    double ABy = yi - bas_y[jsh];
    double ABz = zi - bas_z[jsh];
    double xk = bas_x[ksh];
    double yk = bas_y[ksh];
    double zk = bas_z[ksh];

    prim_ij0 = prim_ij;
    prim_ij1 = prim_ij + nprim_ij;
    prim_kl0 = prim_kl;
    prim_kl1 = prim_kl + nprim_kl;
    double rw[6];
    int irys;
    for (ij = prim_ij0; ij < prim_ij1; ++ij) {
        double alpha = i_exponent[ij];
        double beta = j_exponent[ij];
        double aij = a12[ij];
        double eij = e12[ij];
        double xij = x12[ij];
        double yij = y12[ij];
        double zij = z12[ij];
    for (kl = prim_kl0; kl < prim_kl1; ++kl) {
        double akl = a12[kl];
        double ekl = e12[kl];
        double xkl = x12[kl];
        double ykl = y12[kl];
        double zkl = z12[kl];
        double xijxkl = xij - xkl;
        double yijykl = yij - ykl;
        double zijzkl = zij - zkl;
        double aijkl = aij + akl;
        double a1 = aij * akl;
        double a0 = a1 / aijkl;
        double theta = omega > 0.0 ? omega * omega / (omega * omega + a0) : 1.0; 
        a0 *= theta;
        double x = a0 * (xijxkl * xijxkl + yijykl * yijykl + zijzkl * zijzkl);
        double fac = norm * eij * ekl * sqrt(a0 / (a1 * a1 * a1));
        //double fac = norm * eij * ekl / (sqrt(aijkl) * a1);

        GINTrys_root<3>(x, rw);
        GINTscale_u<3>(rw, theta);
      for (irys = 0; irys < 3; ++irys) {
            double weight0 = rw[irys+3] * fac;
            double root0 = rw[irys];
            double u2 = a0 * root0;
            double tmp4 = .5 / (u2 * aijkl + a1);
            double B00 = u2 * tmp4;
            double tmp1 = 2 * B00;
            double B10 = B00 + tmp4 * akl;
            double tmp2 = tmp1 * akl;
            double C00x = xij - xi - tmp2 * xijxkl;
            double C00y = yij - yi - tmp2 * yijykl;
            double C00z = zij - zi - tmp2 * zijzkl;

            double tmp3 = tmp1 * aij;
            double D00x = xkl - xk + tmp3 * xijxkl;
            double D00y = ykl - yk + tmp3 * yijykl;
            double D00z = zkl - zk + tmp3 * zijzkl;

            double g0 = B10+C00x*C00x;
            double g1 = 3*B10*C00x;
            double g2 = g1+C00x*C00x*C00x;
            double g3 = 3*B10*B10;
            double g4 = 6*B10*C00x*C00x;
            double g5 = g3+g4+C00x*C00x*C00x*C00x;
            double g6 = C00x*D00x;
            double g7 = B00+g6;
            double g8 = 2*B00*C00x;
            double g9 = g0*D00x;
            double g10 = g8+g9;
            double g11 = 3*B00*g0;
            double g12 = 3*B10;
            double g13 = g12+C00x*C00x;
            double g15 = g11+(C00x*g13*D00x);
            double g16 = 4*B00*g2;
            double g17 = g5*D00x;
            double g18 = g16+g17;
            double g19 = ABx+C00x;
            double g21 = B10+(C00x*g19);
            double g23 = g1+C00x*C00x*C00x+(ABx*g0);
            double g26 = ABx+(2*C00x);
            double g28 = g3+(C00x*C00x*C00x*g19)+(3*B10*C00x*g26);
            double g30 = B00+(g19*D00x);
            double g33 = (B00*g26)+(g21*D00x);
            double g41 = (B00*(g12+(C00x*((2*ABx)+(3*C00x)))))+(g23*D00x);
            double g44 = (3*ABx*B00*g0)+g16+(ABx*C00x*g13*D00x)+g17;
            double g45 = B10+C00y*C00y;
            double g46 = 3*B10*C00y;
            double g47 = g46+C00y*C00y*C00y;
            double g49 = g3+(6*B10*C00y*C00y)+C00y*C00y*C00y*C00y;
            double g51 = B00+(C00y*D00y);
            double g54 = (2*B00*C00y)+(g45*D00y);
            double g56 = g12+C00y*C00y;
            double g58 = (3*B00*g45)+(C00y*g56*D00y);
            double g59 = 4*B00*g47;
            double g60 = g49*D00y;
            double g61 = g59+g60;
            double g62 = ABy+C00y;
            double g64 = B10+(C00y*g62);
            double g66 = g46+C00y*C00y*C00y+(ABy*g45);
            double g69 = ABy+(2*C00y);
            double g71 = g3+(C00y*C00y*C00y*g62)+(3*B10*C00y*g69);
            double g73 = B00+(g62*D00y);
            double g76 = (B00*g69)+(g64*D00y);
            double g84 = (B00*(g12+(C00y*((2*ABy)+(3*C00y)))))+(g66*D00y);
            double g87 = (3*ABy*B00*g45)+g59+(ABy*C00y*g56*D00y)+g60;
            double g88 = B10+C00z*C00z;
            double g89 = 3*B10*C00z;
            double g90 = g89+C00z*C00z*C00z;
            double g92 = g3+(6*B10*C00z*C00z)+C00z*C00z*C00z*C00z;
            double g94 = B00+(C00z*D00z);
            double g97 = (2*B00*C00z)+(g88*D00z);
            double g99 = g12+C00z*C00z;
            double g101 = (3*B00*g88)+(C00z*g99*D00z);
            double g102 = 4*B00*g90;
            double g103 = g92*D00z;
            double g104 = g102+g103;
            double g105 = ABz+C00z;
            double g107 = B10+(C00z*g105);
            double g109 = g89+C00z*C00z*C00z+(ABz*g88);
            double g112 = ABz+(2*C00z);
            double g114 = g3+(C00z*C00z*C00z*g105)+(3*B10*C00z*g112);
            double g116 = B00+(g105*D00z);
            double g119 = (B00*g112)+(g107*D00z);
            double g127 = (B00*(g12+(C00z*((2*ABz)+(3*C00z)))))+(g109*D00z);
            double g130 = (3*ABz*B00*g88)+g102+(ABz*C00z*g99*D00z)+g103;

            gout0 += (-3*g10 + 2*alpha*g18) * weight0;
            gout1 += (-3*g0 + 2*alpha*g5) * (D00y) * weight0;
            gout2 += (-3*g0 + 2*alpha*g5) * (D00z) * weight0;
            gout3 += (-2*g7 + 2*alpha*g15) * (C00y) * weight0;
            gout4 += (-2*C00x + 2*alpha*g2) * (g51) * weight0;
            gout5 += (-2*C00x + 2*alpha*g2) * (C00y) * (D00z) * weight0;
            gout6 += (-2*g7 + 2*alpha*g15) * (C00z) * weight0;
            gout7 += (-2*C00x + 2*alpha*g2) * (D00y) * (C00z) * weight0;
            gout8 += (-2*C00x + 2*alpha*g2) * (g94) * weight0;
            gout9 += (-D00x + 2*alpha*g10) * (g45) * weight0;
            gout10 += (-1 + 2*alpha*g0) * (g54) * weight0;
            gout11 += (-1 + 2*alpha*g0) * (g45) * (D00z) * weight0;
            gout12 += (-D00x + 2*alpha*g10) * (C00y) * (C00z) * weight0;
            gout13 += (-1 + 2*alpha*g0) * (g51) * (C00z) * weight0;
            gout14 += (-1 + 2*alpha*g0) * (C00y) * (g94) * weight0;
            gout15 += (-D00x + 2*alpha*g10) * (g88) * weight0;
            gout16 += (-1 + 2*alpha*g0) * (D00y) * (g88) * weight0;
            gout17 += (-1 + 2*alpha*g0) * (g97) * weight0;
            gout18 += (2*alpha*g7) * (g47) * weight0;
            gout19 += (2*alpha*C00x) * (g58) * weight0;
            gout20 += (2*alpha*C00x) * (g47) * (D00z) * weight0;
            gout21 += (2*alpha*g7) * (g45) * (C00z) * weight0;
            gout22 += (2*alpha*C00x) * (g54) * (C00z) * weight0;
            gout23 += (2*alpha*C00x) * (g45) * (g94) * weight0;
            gout24 += (2*alpha*g7) * (C00y) * (g88) * weight0;
            gout25 += (2*alpha*C00x) * (g51) * (g88) * weight0;
            gout26 += (2*alpha*C00x) * (C00y) * (g97) * weight0;
            gout27 += (2*alpha*g7) * (g90) * weight0;
            gout28 += (2*alpha*C00x) * (D00y) * (g90) * weight0;
            gout29 += (2*alpha*C00x) * (g101) * weight0;
            gout30 += (g15) * (2*alpha*C00y) * weight0;
            gout31 += (g2) * (2*alpha*g51) * weight0;
            gout32 += (g2) * (2*alpha*C00y) * (D00z) * weight0;
            gout33 += (g10) * (-1 + 2*alpha*g45) * weight0;
            gout34 += (g0) * (-D00y + 2*alpha*g54) * weight0;
            gout35 += (g0) * (-1 + 2*alpha*g45) * (D00z) * weight0;
            gout36 += (g10) * (2*alpha*C00y) * (C00z) * weight0;
            gout37 += (g0) * (2*alpha*g51) * (C00z) * weight0;
            gout38 += (g0) * (2*alpha*C00y) * (g94) * weight0;
            gout39 += (g7) * (-2*C00y + 2*alpha*g47) * weight0;
            gout40 += (C00x) * (-2*g51 + 2*alpha*g58) * weight0;
            gout41 += (C00x) * (-2*C00y + 2*alpha*g47) * (D00z) * weight0;
            gout42 += (g7) * (-1 + 2*alpha*g45) * (C00z) * weight0;
            gout43 += (C00x) * (-D00y + 2*alpha*g54) * (C00z) * weight0;
            gout44 += (C00x) * (-1 + 2*alpha*g45) * (g94) * weight0;
            gout45 += (g7) * (2*alpha*C00y) * (g88) * weight0;
            gout46 += (C00x) * (2*alpha*g51) * (g88) * weight0;
            gout47 += (C00x) * (2*alpha*C00y) * (g97) * weight0;
            gout48 += (D00x) * (-3*g45 + 2*alpha*g49) * weight0;
            gout49 += (-3*g54 + 2*alpha*g61) * weight0;
            gout50 += (-3*g45 + 2*alpha*g49) * (D00z) * weight0;
            gout51 += (D00x) * (-2*C00y + 2*alpha*g47) * (C00z) * weight0;
            gout52 += (-2*g51 + 2*alpha*g58) * (C00z) * weight0;
            gout53 += (-2*C00y + 2*alpha*g47) * (g94) * weight0;
            gout54 += (D00x) * (-1 + 2*alpha*g45) * (g88) * weight0;
            gout55 += (-D00y + 2*alpha*g54) * (g88) * weight0;
            gout56 += (-1 + 2*alpha*g45) * (g97) * weight0;
            gout57 += (D00x) * (2*alpha*C00y) * (g90) * weight0;
            gout58 += (2*alpha*g51) * (g90) * weight0;
            gout59 += (2*alpha*C00y) * (g101) * weight0;
            gout60 += (g15) * (2*alpha*C00z) * weight0;
            gout61 += (g2) * (D00y) * (2*alpha*C00z) * weight0;
            gout62 += (g2) * (2*alpha*g94) * weight0;
            gout63 += (g10) * (C00y) * (2*alpha*C00z) * weight0;
            gout64 += (g0) * (g51) * (2*alpha*C00z) * weight0;
            gout65 += (g0) * (C00y) * (2*alpha*g94) * weight0;
            gout66 += (g10) * (-1 + 2*alpha*g88) * weight0;
            gout67 += (g0) * (D00y) * (-1 + 2*alpha*g88) * weight0;
            gout68 += (g0) * (-D00z + 2*alpha*g97) * weight0;
            gout69 += (g7) * (g45) * (2*alpha*C00z) * weight0;
            gout70 += (C00x) * (g54) * (2*alpha*C00z) * weight0;
            gout71 += (C00x) * (g45) * (2*alpha*g94) * weight0;
            gout72 += (g7) * (C00y) * (-1 + 2*alpha*g88) * weight0;
            gout73 += (C00x) * (g51) * (-1 + 2*alpha*g88) * weight0;
            gout74 += (C00x) * (C00y) * (-D00z + 2*alpha*g97) * weight0;
            gout75 += (g7) * (-2*C00z + 2*alpha*g90) * weight0;
            gout76 += (C00x) * (D00y) * (-2*C00z + 2*alpha*g90) * weight0;
            gout77 += (C00x) * (-2*g94 + 2*alpha*g101) * weight0;
            gout78 += (D00x) * (g47) * (2*alpha*C00z) * weight0;
            gout79 += (g58) * (2*alpha*C00z) * weight0;
            gout80 += (g47) * (2*alpha*g94) * weight0;
            gout81 += (D00x) * (g45) * (-1 + 2*alpha*g88) * weight0;
            gout82 += (g54) * (-1 + 2*alpha*g88) * weight0;
            gout83 += (g45) * (-D00z + 2*alpha*g97) * weight0;
            gout84 += (D00x) * (C00y) * (-2*C00z + 2*alpha*g90) * weight0;
            gout85 += (g51) * (-2*C00z + 2*alpha*g90) * weight0;
            gout86 += (C00y) * (-2*g94 + 2*alpha*g101) * weight0;
            gout87 += (D00x) * (-3*g88 + 2*alpha*g92) * weight0;
            gout88 += (D00y) * (-3*g88 + 2*alpha*g92) * weight0;
            gout89 += (-3*g97 + 2*alpha*g104) * weight0;
            gout90 += (2*beta*g44) * weight0;
            gout91 += (2*beta*g28) * (D00y) * weight0;
            gout92 += (2*beta*g28) * (D00z) * weight0;
            gout93 += (2*beta*g41) * (C00y) * weight0;
            gout94 += (2*beta*g23) * (g51) * weight0;
            gout95 += (2*beta*g23) * (C00y) * (D00z) * weight0;
            gout96 += (2*beta*g41) * (C00z) * weight0;
            gout97 += (2*beta*g23) * (D00y) * (C00z) * weight0;
            gout98 += (2*beta*g23) * (g94) * weight0;
            gout99 += (2*beta*g33) * (g45) * weight0;
            gout100 += (2*beta*g21) * (g54) * weight0;
            gout101 += (2*beta*g21) * (g45) * (D00z) * weight0;
            gout102 += (2*beta*g33) * (C00y) * (C00z) * weight0;
            gout103 += (2*beta*g21) * (g51) * (C00z) * weight0;
            gout104 += (2*beta*g21) * (C00y) * (g94) * weight0;
            gout105 += (2*beta*g33) * (g88) * weight0;
            gout106 += (2*beta*g21) * (D00y) * (g88) * weight0;
            gout107 += (2*beta*g21) * (g97) * weight0;
            gout108 += (2*beta*g30) * (g47) * weight0;
            gout109 += (2*beta*g19) * (g58) * weight0;
            gout110 += (2*beta*g19) * (g47) * (D00z) * weight0;
            gout111 += (2*beta*g30) * (g45) * (C00z) * weight0;
            gout112 += (2*beta*g19) * (g54) * (C00z) * weight0;
            gout113 += (2*beta*g19) * (g45) * (g94) * weight0;
            gout114 += (2*beta*g30) * (C00y) * (g88) * weight0;
            gout115 += (2*beta*g19) * (g51) * (g88) * weight0;
            gout116 += (2*beta*g19) * (C00y) * (g97) * weight0;
            gout117 += (2*beta*g30) * (g90) * weight0;
            gout118 += (2*beta*g19) * (D00y) * (g90) * weight0;
            gout119 += (2*beta*g19) * (g101) * weight0;
            gout120 += (g15) * (2*beta*g62) * weight0;
            gout121 += (g2) * (2*beta*g73) * weight0;
            gout122 += (g2) * (2*beta*g62) * (D00z) * weight0;
            gout123 += (g10) * (2*beta*g64) * weight0;
            gout124 += (g0) * (2*beta*g76) * weight0;
            gout125 += (g0) * (2*beta*g64) * (D00z) * weight0;
            gout126 += (g10) * (2*beta*g62) * (C00z) * weight0;
            gout127 += (g0) * (2*beta*g73) * (C00z) * weight0;
            gout128 += (g0) * (2*beta*g62) * (g94) * weight0;
            gout129 += (g7) * (2*beta*g66) * weight0;
            gout130 += (C00x) * (2*beta*g84) * weight0;
            gout131 += (C00x) * (2*beta*g66) * (D00z) * weight0;
            gout132 += (g7) * (2*beta*g64) * (C00z) * weight0;
            gout133 += (C00x) * (2*beta*g76) * (C00z) * weight0;
            gout134 += (C00x) * (2*beta*g64) * (g94) * weight0;
            gout135 += (g7) * (2*beta*g62) * (g88) * weight0;
            gout136 += (C00x) * (2*beta*g73) * (g88) * weight0;
            gout137 += (C00x) * (2*beta*g62) * (g97) * weight0;
            gout138 += (D00x) * (2*beta*g71) * weight0;
            gout139 += (2*beta*g87) * weight0;
            gout140 += (2*beta*g71) * (D00z) * weight0;
            gout141 += (D00x) * (2*beta*g66) * (C00z) * weight0;
            gout142 += (2*beta*g84) * (C00z) * weight0;
            gout143 += (2*beta*g66) * (g94) * weight0;
            gout144 += (D00x) * (2*beta*g64) * (g88) * weight0;
            gout145 += (2*beta*g76) * (g88) * weight0;
            gout146 += (2*beta*g64) * (g97) * weight0;
            gout147 += (D00x) * (2*beta*g62) * (g90) * weight0;
            gout148 += (2*beta*g73) * (g90) * weight0;
            gout149 += (2*beta*g62) * (g101) * weight0;
            gout150 += (g15) * (2*beta*g105) * weight0;
            gout151 += (g2) * (D00y) * (2*beta*g105) * weight0;
            gout152 += (g2) * (2*beta*g116) * weight0;
            gout153 += (g10) * (C00y) * (2*beta*g105) * weight0;
            gout154 += (g0) * (g51) * (2*beta*g105) * weight0;
            gout155 += (g0) * (C00y) * (2*beta*g116) * weight0;
            gout156 += (g10) * (2*beta*g107) * weight0;
            gout157 += (g0) * (D00y) * (2*beta*g107) * weight0;
            gout158 += (g0) * (2*beta*g119) * weight0;
            gout159 += (g7) * (g45) * (2*beta*g105) * weight0;
            gout160 += (C00x) * (g54) * (2*beta*g105) * weight0;
            gout161 += (C00x) * (g45) * (2*beta*g116) * weight0;
            gout162 += (g7) * (C00y) * (2*beta*g107) * weight0;
            gout163 += (C00x) * (g51) * (2*beta*g107) * weight0;
            gout164 += (C00x) * (C00y) * (2*beta*g119) * weight0;
            gout165 += (g7) * (2*beta*g109) * weight0;
            gout166 += (C00x) * (D00y) * (2*beta*g109) * weight0;
            gout167 += (C00x) * (2*beta*g127) * weight0;
            gout168 += (D00x) * (g47) * (2*beta*g105) * weight0;
            gout169 += (g58) * (2*beta*g105) * weight0;
            gout170 += (g47) * (2*beta*g116) * weight0;
            gout171 += (D00x) * (g45) * (2*beta*g107) * weight0;
            gout172 += (g54) * (2*beta*g107) * weight0;
            gout173 += (g45) * (2*beta*g119) * weight0;
            gout174 += (D00x) * (C00y) * (2*beta*g109) * weight0;
            gout175 += (g51) * (2*beta*g109) * weight0;
            gout176 += (C00y) * (2*beta*g127) * weight0;
            gout177 += (D00x) * (2*beta*g114) * weight0;
            gout178 += (D00y) * (2*beta*g114) * weight0;
            gout179 += (2*beta*g130) * weight0;
        }
    } }

    int *ao_loc = c_bpcache.ao_loc;
    int i0 = ao_loc[ish];
    int j0 = ao_loc[jsh];
    int k0 = ao_loc[ksh];
    int l0 = ao_loc[lsh];
    int n_dm = jk.n_dm;
    int nao = jk.nao;
    size_t nao2 = nao * nao;
    double* __restrict__ dm = jk.dm;
    double *vj = jk.vj;
    double *vk = jk.vk;
    double d_0, d_1, d_2, d_3, d_4, d_5, d_6, d_7, d_8, d_9, d_10, d_11, d_12, d_13, d_14, d_15, d_16, d_17, d_18, d_19, d_20, d_21, d_22, d_23, d_24, d_25, d_26, d_27, d_28, d_29;

    for (int i_dm = 0; i_dm < n_dm; ++i_dm) {
        if (vj != NULL) {
            d_0 = dm[(k0+0)+nao*(l0+0)];
            d_1 = dm[(k0+1)+nao*(l0+0)];
            d_2 = dm[(k0+2)+nao*(l0+0)];
            atomicAdd(vj+(i0+0)+nao*(j0+0), gout0*d_0+gout1*d_1+gout2*d_2);
            atomicAdd(vj+(i0+1)+nao*(j0+0), gout3*d_0+gout4*d_1+gout5*d_2);
            atomicAdd(vj+(i0+2)+nao*(j0+0), gout6*d_0+gout7*d_1+gout8*d_2);
            atomicAdd(vj+(i0+3)+nao*(j0+0), gout9*d_0+gout10*d_1+gout11*d_2);
            atomicAdd(vj+(i0+4)+nao*(j0+0), gout12*d_0+gout13*d_1+gout14*d_2);
            atomicAdd(vj+(i0+5)+nao*(j0+0), gout15*d_0+gout16*d_1+gout17*d_2);
            atomicAdd(vj+(i0+6)+nao*(j0+0), gout18*d_0+gout19*d_1+gout20*d_2);
            atomicAdd(vj+(i0+7)+nao*(j0+0), gout21*d_0+gout22*d_1+gout23*d_2);
            atomicAdd(vj+(i0+8)+nao*(j0+0), gout24*d_0+gout25*d_1+gout26*d_2);
            atomicAdd(vj+(i0+9)+nao*(j0+0), gout27*d_0+gout28*d_1+gout29*d_2);
            atomicAdd(vj+(i0+0)+nao*(j0+0)+nao2, gout30*d_0+gout31*d_1+gout32*d_2);
            atomicAdd(vj+(i0+1)+nao*(j0+0)+nao2, gout33*d_0+gout34*d_1+gout35*d_2);
            atomicAdd(vj+(i0+2)+nao*(j0+0)+nao2, gout36*d_0+gout37*d_1+gout38*d_2);
            atomicAdd(vj+(i0+3)+nao*(j0+0)+nao2, gout39*d_0+gout40*d_1+gout41*d_2);
            atomicAdd(vj+(i0+4)+nao*(j0+0)+nao2, gout42*d_0+gout43*d_1+gout44*d_2);
            atomicAdd(vj+(i0+5)+nao*(j0+0)+nao2, gout45*d_0+gout46*d_1+gout47*d_2);
            atomicAdd(vj+(i0+6)+nao*(j0+0)+nao2, gout48*d_0+gout49*d_1+gout50*d_2);
            atomicAdd(vj+(i0+7)+nao*(j0+0)+nao2, gout51*d_0+gout52*d_1+gout53*d_2);
            atomicAdd(vj+(i0+8)+nao*(j0+0)+nao2, gout54*d_0+gout55*d_1+gout56*d_2);
            atomicAdd(vj+(i0+9)+nao*(j0+0)+nao2, gout57*d_0+gout58*d_1+gout59*d_2);
            atomicAdd(vj+(i0+0)+nao*(j0+0)+2*nao2, gout60*d_0+gout61*d_1+gout62*d_2);
            atomicAdd(vj+(i0+1)+nao*(j0+0)+2*nao2, gout63*d_0+gout64*d_1+gout65*d_2);
            atomicAdd(vj+(i0+2)+nao*(j0+0)+2*nao2, gout66*d_0+gout67*d_1+gout68*d_2);
            atomicAdd(vj+(i0+3)+nao*(j0+0)+2*nao2, gout69*d_0+gout70*d_1+gout71*d_2);
            atomicAdd(vj+(i0+4)+nao*(j0+0)+2*nao2, gout72*d_0+gout73*d_1+gout74*d_2);
            atomicAdd(vj+(i0+5)+nao*(j0+0)+2*nao2, gout75*d_0+gout76*d_1+gout77*d_2);
            atomicAdd(vj+(i0+6)+nao*(j0+0)+2*nao2, gout78*d_0+gout79*d_1+gout80*d_2);
            atomicAdd(vj+(i0+7)+nao*(j0+0)+2*nao2, gout81*d_0+gout82*d_1+gout83*d_2);
            atomicAdd(vj+(i0+8)+nao*(j0+0)+2*nao2, gout84*d_0+gout85*d_1+gout86*d_2);
            atomicAdd(vj+(i0+9)+nao*(j0+0)+2*nao2, gout87*d_0+gout88*d_1+gout89*d_2);
            atomicAdd(vj+nao*(i0+0)+(j0+0), gout90*d_0+gout91*d_1+gout92*d_2);
            atomicAdd(vj+nao*(i0+1)+(j0+0), gout93*d_0+gout94*d_1+gout95*d_2);
            atomicAdd(vj+nao*(i0+2)+(j0+0), gout96*d_0+gout97*d_1+gout98*d_2);
            atomicAdd(vj+nao*(i0+3)+(j0+0), gout99*d_0+gout100*d_1+gout101*d_2);
            atomicAdd(vj+nao*(i0+4)+(j0+0), gout102*d_0+gout103*d_1+gout104*d_2);
            atomicAdd(vj+nao*(i0+5)+(j0+0), gout105*d_0+gout106*d_1+gout107*d_2);
            atomicAdd(vj+nao*(i0+6)+(j0+0), gout108*d_0+gout109*d_1+gout110*d_2);
            atomicAdd(vj+nao*(i0+7)+(j0+0), gout111*d_0+gout112*d_1+gout113*d_2);
            atomicAdd(vj+nao*(i0+8)+(j0+0), gout114*d_0+gout115*d_1+gout116*d_2);
            atomicAdd(vj+nao*(i0+9)+(j0+0), gout117*d_0+gout118*d_1+gout119*d_2);
            atomicAdd(vj+nao*(i0+0)+(j0+0)+nao2, gout120*d_0+gout121*d_1+gout122*d_2);
            atomicAdd(vj+nao*(i0+1)+(j0+0)+nao2, gout123*d_0+gout124*d_1+gout125*d_2);
            atomicAdd(vj+nao*(i0+2)+(j0+0)+nao2, gout126*d_0+gout127*d_1+gout128*d_2);
            atomicAdd(vj+nao*(i0+3)+(j0+0)+nao2, gout129*d_0+gout130*d_1+gout131*d_2);
            atomicAdd(vj+nao*(i0+4)+(j0+0)+nao2, gout132*d_0+gout133*d_1+gout134*d_2);
            atomicAdd(vj+nao*(i0+5)+(j0+0)+nao2, gout135*d_0+gout136*d_1+gout137*d_2);
            atomicAdd(vj+nao*(i0+6)+(j0+0)+nao2, gout138*d_0+gout139*d_1+gout140*d_2);
            atomicAdd(vj+nao*(i0+7)+(j0+0)+nao2, gout141*d_0+gout142*d_1+gout143*d_2);
            atomicAdd(vj+nao*(i0+8)+(j0+0)+nao2, gout144*d_0+gout145*d_1+gout146*d_2);
            atomicAdd(vj+nao*(i0+9)+(j0+0)+nao2, gout147*d_0+gout148*d_1+gout149*d_2);
            atomicAdd(vj+nao*(i0+0)+(j0+0)+2*nao2, gout150*d_0+gout151*d_1+gout152*d_2);
            atomicAdd(vj+nao*(i0+1)+(j0+0)+2*nao2, gout153*d_0+gout154*d_1+gout155*d_2);
            atomicAdd(vj+nao*(i0+2)+(j0+0)+2*nao2, gout156*d_0+gout157*d_1+gout158*d_2);
            atomicAdd(vj+nao*(i0+3)+(j0+0)+2*nao2, gout159*d_0+gout160*d_1+gout161*d_2);
            atomicAdd(vj+nao*(i0+4)+(j0+0)+2*nao2, gout162*d_0+gout163*d_1+gout164*d_2);
            atomicAdd(vj+nao*(i0+5)+(j0+0)+2*nao2, gout165*d_0+gout166*d_1+gout167*d_2);
            atomicAdd(vj+nao*(i0+6)+(j0+0)+2*nao2, gout168*d_0+gout169*d_1+gout170*d_2);
            atomicAdd(vj+nao*(i0+7)+(j0+0)+2*nao2, gout171*d_0+gout172*d_1+gout173*d_2);
            atomicAdd(vj+nao*(i0+8)+(j0+0)+2*nao2, gout174*d_0+gout175*d_1+gout176*d_2);
            atomicAdd(vj+nao*(i0+9)+(j0+0)+2*nao2, gout177*d_0+gout178*d_1+gout179*d_2);
            vj += 3*nao2;
        }
        if (vk != NULL) {
            // ijkl, jk -> il
            d_0 = dm[(j0+0)+nao*(k0+0)];
            d_1 = dm[(j0+0)+nao*(k0+1)];
            d_2 = dm[(j0+0)+nao*(k0+2)];
            atomicAdd(vk+(i0+0)+nao*(l0+0), gout0*d_0+gout1*d_1+gout2*d_2);
            atomicAdd(vk+(i0+1)+nao*(l0+0), gout3*d_0+gout4*d_1+gout5*d_2);
            atomicAdd(vk+(i0+2)+nao*(l0+0), gout6*d_0+gout7*d_1+gout8*d_2);
            atomicAdd(vk+(i0+3)+nao*(l0+0), gout9*d_0+gout10*d_1+gout11*d_2);
            atomicAdd(vk+(i0+4)+nao*(l0+0), gout12*d_0+gout13*d_1+gout14*d_2);
            atomicAdd(vk+(i0+5)+nao*(l0+0), gout15*d_0+gout16*d_1+gout17*d_2);
            atomicAdd(vk+(i0+6)+nao*(l0+0), gout18*d_0+gout19*d_1+gout20*d_2);
            atomicAdd(vk+(i0+7)+nao*(l0+0), gout21*d_0+gout22*d_1+gout23*d_2);
            atomicAdd(vk+(i0+8)+nao*(l0+0), gout24*d_0+gout25*d_1+gout26*d_2);
            atomicAdd(vk+(i0+9)+nao*(l0+0), gout27*d_0+gout28*d_1+gout29*d_2);
            atomicAdd(vk+(i0+0)+nao*(l0+0)+nao2, gout30*d_0+gout31*d_1+gout32*d_2);
            atomicAdd(vk+(i0+1)+nao*(l0+0)+nao2, gout33*d_0+gout34*d_1+gout35*d_2);
            atomicAdd(vk+(i0+2)+nao*(l0+0)+nao2, gout36*d_0+gout37*d_1+gout38*d_2);
            atomicAdd(vk+(i0+3)+nao*(l0+0)+nao2, gout39*d_0+gout40*d_1+gout41*d_2);
            atomicAdd(vk+(i0+4)+nao*(l0+0)+nao2, gout42*d_0+gout43*d_1+gout44*d_2);
            atomicAdd(vk+(i0+5)+nao*(l0+0)+nao2, gout45*d_0+gout46*d_1+gout47*d_2);
            atomicAdd(vk+(i0+6)+nao*(l0+0)+nao2, gout48*d_0+gout49*d_1+gout50*d_2);
            atomicAdd(vk+(i0+7)+nao*(l0+0)+nao2, gout51*d_0+gout52*d_1+gout53*d_2);
            atomicAdd(vk+(i0+8)+nao*(l0+0)+nao2, gout54*d_0+gout55*d_1+gout56*d_2);
            atomicAdd(vk+(i0+9)+nao*(l0+0)+nao2, gout57*d_0+gout58*d_1+gout59*d_2);
            atomicAdd(vk+(i0+0)+nao*(l0+0)+2*nao2, gout60*d_0+gout61*d_1+gout62*d_2);
            atomicAdd(vk+(i0+1)+nao*(l0+0)+2*nao2, gout63*d_0+gout64*d_1+gout65*d_2);
            atomicAdd(vk+(i0+2)+nao*(l0+0)+2*nao2, gout66*d_0+gout67*d_1+gout68*d_2);
            atomicAdd(vk+(i0+3)+nao*(l0+0)+2*nao2, gout69*d_0+gout70*d_1+gout71*d_2);
            atomicAdd(vk+(i0+4)+nao*(l0+0)+2*nao2, gout72*d_0+gout73*d_1+gout74*d_2);
            atomicAdd(vk+(i0+5)+nao*(l0+0)+2*nao2, gout75*d_0+gout76*d_1+gout77*d_2);
            atomicAdd(vk+(i0+6)+nao*(l0+0)+2*nao2, gout78*d_0+gout79*d_1+gout80*d_2);
            atomicAdd(vk+(i0+7)+nao*(l0+0)+2*nao2, gout81*d_0+gout82*d_1+gout83*d_2);
            atomicAdd(vk+(i0+8)+nao*(l0+0)+2*nao2, gout84*d_0+gout85*d_1+gout86*d_2);
            atomicAdd(vk+(i0+9)+nao*(l0+0)+2*nao2, gout87*d_0+gout88*d_1+gout89*d_2);
            // ijkl, jl -> ik
            d_0 = dm[(j0+0)+nao*(l0+0)];
            atomicAdd(vk+(i0+0)+nao*(k0+0), gout0*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+1), gout1*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+2), gout2*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+0), gout3*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+1), gout4*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+2), gout5*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+0), gout6*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+1), gout7*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+2), gout8*d_0);
            atomicAdd(vk+(i0+3)+nao*(k0+0), gout9*d_0);
            atomicAdd(vk+(i0+3)+nao*(k0+1), gout10*d_0);
            atomicAdd(vk+(i0+3)+nao*(k0+2), gout11*d_0);
            atomicAdd(vk+(i0+4)+nao*(k0+0), gout12*d_0);
            atomicAdd(vk+(i0+4)+nao*(k0+1), gout13*d_0);
            atomicAdd(vk+(i0+4)+nao*(k0+2), gout14*d_0);
            atomicAdd(vk+(i0+5)+nao*(k0+0), gout15*d_0);
            atomicAdd(vk+(i0+5)+nao*(k0+1), gout16*d_0);
            atomicAdd(vk+(i0+5)+nao*(k0+2), gout17*d_0);
            atomicAdd(vk+(i0+6)+nao*(k0+0), gout18*d_0);
            atomicAdd(vk+(i0+6)+nao*(k0+1), gout19*d_0);
            atomicAdd(vk+(i0+6)+nao*(k0+2), gout20*d_0);
            atomicAdd(vk+(i0+7)+nao*(k0+0), gout21*d_0);
            atomicAdd(vk+(i0+7)+nao*(k0+1), gout22*d_0);
            atomicAdd(vk+(i0+7)+nao*(k0+2), gout23*d_0);
            atomicAdd(vk+(i0+8)+nao*(k0+0), gout24*d_0);
            atomicAdd(vk+(i0+8)+nao*(k0+1), gout25*d_0);
            atomicAdd(vk+(i0+8)+nao*(k0+2), gout26*d_0);
            atomicAdd(vk+(i0+9)+nao*(k0+0), gout27*d_0);
            atomicAdd(vk+(i0+9)+nao*(k0+1), gout28*d_0);
            atomicAdd(vk+(i0+9)+nao*(k0+2), gout29*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+0)+nao2, gout30*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+1)+nao2, gout31*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+2)+nao2, gout32*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+0)+nao2, gout33*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+1)+nao2, gout34*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+2)+nao2, gout35*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+0)+nao2, gout36*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+1)+nao2, gout37*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+2)+nao2, gout38*d_0);
            atomicAdd(vk+(i0+3)+nao*(k0+0)+nao2, gout39*d_0);
            atomicAdd(vk+(i0+3)+nao*(k0+1)+nao2, gout40*d_0);
            atomicAdd(vk+(i0+3)+nao*(k0+2)+nao2, gout41*d_0);
            atomicAdd(vk+(i0+4)+nao*(k0+0)+nao2, gout42*d_0);
            atomicAdd(vk+(i0+4)+nao*(k0+1)+nao2, gout43*d_0);
            atomicAdd(vk+(i0+4)+nao*(k0+2)+nao2, gout44*d_0);
            atomicAdd(vk+(i0+5)+nao*(k0+0)+nao2, gout45*d_0);
            atomicAdd(vk+(i0+5)+nao*(k0+1)+nao2, gout46*d_0);
            atomicAdd(vk+(i0+5)+nao*(k0+2)+nao2, gout47*d_0);
            atomicAdd(vk+(i0+6)+nao*(k0+0)+nao2, gout48*d_0);
            atomicAdd(vk+(i0+6)+nao*(k0+1)+nao2, gout49*d_0);
            atomicAdd(vk+(i0+6)+nao*(k0+2)+nao2, gout50*d_0);
            atomicAdd(vk+(i0+7)+nao*(k0+0)+nao2, gout51*d_0);
            atomicAdd(vk+(i0+7)+nao*(k0+1)+nao2, gout52*d_0);
            atomicAdd(vk+(i0+7)+nao*(k0+2)+nao2, gout53*d_0);
            atomicAdd(vk+(i0+8)+nao*(k0+0)+nao2, gout54*d_0);
            atomicAdd(vk+(i0+8)+nao*(k0+1)+nao2, gout55*d_0);
            atomicAdd(vk+(i0+8)+nao*(k0+2)+nao2, gout56*d_0);
            atomicAdd(vk+(i0+9)+nao*(k0+0)+nao2, gout57*d_0);
            atomicAdd(vk+(i0+9)+nao*(k0+1)+nao2, gout58*d_0);
            atomicAdd(vk+(i0+9)+nao*(k0+2)+nao2, gout59*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+0)+2*nao2, gout60*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+1)+2*nao2, gout61*d_0);
            atomicAdd(vk+(i0+0)+nao*(k0+2)+2*nao2, gout62*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+0)+2*nao2, gout63*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+1)+2*nao2, gout64*d_0);
            atomicAdd(vk+(i0+1)+nao*(k0+2)+2*nao2, gout65*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+0)+2*nao2, gout66*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+1)+2*nao2, gout67*d_0);
            atomicAdd(vk+(i0+2)+nao*(k0+2)+2*nao2, gout68*d_0);
            atomicAdd(vk+(i0+3)+nao*(k0+0)+2*nao2, gout69*d_0);
            atomicAdd(vk+(i0+3)+nao*(k0+1)+2*nao2, gout70*d_0);
            atomicAdd(vk+(i0+3)+nao*(k0+2)+2*nao2, gout71*d_0);
            atomicAdd(vk+(i0+4)+nao*(k0+0)+2*nao2, gout72*d_0);
            atomicAdd(vk+(i0+4)+nao*(k0+1)+2*nao2, gout73*d_0);
            atomicAdd(vk+(i0+4)+nao*(k0+2)+2*nao2, gout74*d_0);
            atomicAdd(vk+(i0+5)+nao*(k0+0)+2*nao2, gout75*d_0);
            atomicAdd(vk+(i0+5)+nao*(k0+1)+2*nao2, gout76*d_0);
            atomicAdd(vk+(i0+5)+nao*(k0+2)+2*nao2, gout77*d_0);
            atomicAdd(vk+(i0+6)+nao*(k0+0)+2*nao2, gout78*d_0);
            atomicAdd(vk+(i0+6)+nao*(k0+1)+2*nao2, gout79*d_0);
            atomicAdd(vk+(i0+6)+nao*(k0+2)+2*nao2, gout80*d_0);
            atomicAdd(vk+(i0+7)+nao*(k0+0)+2*nao2, gout81*d_0);
            atomicAdd(vk+(i0+7)+nao*(k0+1)+2*nao2, gout82*d_0);
            atomicAdd(vk+(i0+7)+nao*(k0+2)+2*nao2, gout83*d_0);
            atomicAdd(vk+(i0+8)+nao*(k0+0)+2*nao2, gout84*d_0);
            atomicAdd(vk+(i0+8)+nao*(k0+1)+2*nao2, gout85*d_0);
            atomicAdd(vk+(i0+8)+nao*(k0+2)+2*nao2, gout86*d_0);
            atomicAdd(vk+(i0+9)+nao*(k0+0)+2*nao2, gout87*d_0);
            atomicAdd(vk+(i0+9)+nao*(k0+1)+2*nao2, gout88*d_0);
            atomicAdd(vk+(i0+9)+nao*(k0+2)+2*nao2, gout89*d_0);
            // ijkl, ik -> jl
            d_0 = dm[(i0+0)+nao*(k0+0)];
            d_1 = dm[(i0+0)+nao*(k0+1)];
            d_2 = dm[(i0+0)+nao*(k0+2)];
            d_3 = dm[(i0+1)+nao*(k0+0)];
            d_4 = dm[(i0+1)+nao*(k0+1)];
            d_5 = dm[(i0+1)+nao*(k0+2)];
            d_6 = dm[(i0+2)+nao*(k0+0)];
            d_7 = dm[(i0+2)+nao*(k0+1)];
            d_8 = dm[(i0+2)+nao*(k0+2)];
            d_9 = dm[(i0+3)+nao*(k0+0)];
            d_10 = dm[(i0+3)+nao*(k0+1)];
            d_11 = dm[(i0+3)+nao*(k0+2)];
            d_12 = dm[(i0+4)+nao*(k0+0)];
            d_13 = dm[(i0+4)+nao*(k0+1)];
            d_14 = dm[(i0+4)+nao*(k0+2)];
            d_15 = dm[(i0+5)+nao*(k0+0)];
            d_16 = dm[(i0+5)+nao*(k0+1)];
            d_17 = dm[(i0+5)+nao*(k0+2)];
            d_18 = dm[(i0+6)+nao*(k0+0)];
            d_19 = dm[(i0+6)+nao*(k0+1)];
            d_20 = dm[(i0+6)+nao*(k0+2)];
            d_21 = dm[(i0+7)+nao*(k0+0)];
            d_22 = dm[(i0+7)+nao*(k0+1)];
            d_23 = dm[(i0+7)+nao*(k0+2)];
            d_24 = dm[(i0+8)+nao*(k0+0)];
            d_25 = dm[(i0+8)+nao*(k0+1)];
            d_26 = dm[(i0+8)+nao*(k0+2)];
            d_27 = dm[(i0+9)+nao*(k0+0)];
            d_28 = dm[(i0+9)+nao*(k0+1)];
            d_29 = dm[(i0+9)+nao*(k0+2)];
            atomicAdd(vk+(j0+0)+nao*(l0+0), gout90*d_0+gout91*d_1+gout92*d_2+gout93*d_3+gout94*d_4+gout95*d_5+gout96*d_6+gout97*d_7+gout98*d_8+gout99*d_9+gout100*d_10+gout101*d_11+gout102*d_12+gout103*d_13+gout104*d_14+gout105*d_15+gout106*d_16+gout107*d_17+gout108*d_18+gout109*d_19+gout110*d_20+gout111*d_21+gout112*d_22+gout113*d_23+gout114*d_24+gout115*d_25+gout116*d_26+gout117*d_27+gout118*d_28+gout119*d_29);
            atomicAdd(vk+(j0+0)+nao*(l0+0)+nao2, gout120*d_0+gout121*d_1+gout122*d_2+gout123*d_3+gout124*d_4+gout125*d_5+gout126*d_6+gout127*d_7+gout128*d_8+gout129*d_9+gout130*d_10+gout131*d_11+gout132*d_12+gout133*d_13+gout134*d_14+gout135*d_15+gout136*d_16+gout137*d_17+gout138*d_18+gout139*d_19+gout140*d_20+gout141*d_21+gout142*d_22+gout143*d_23+gout144*d_24+gout145*d_25+gout146*d_26+gout147*d_27+gout148*d_28+gout149*d_29);
            atomicAdd(vk+(j0+0)+nao*(l0+0)+2*nao2, gout150*d_0+gout151*d_1+gout152*d_2+gout153*d_3+gout154*d_4+gout155*d_5+gout156*d_6+gout157*d_7+gout158*d_8+gout159*d_9+gout160*d_10+gout161*d_11+gout162*d_12+gout163*d_13+gout164*d_14+gout165*d_15+gout166*d_16+gout167*d_17+gout168*d_18+gout169*d_19+gout170*d_20+gout171*d_21+gout172*d_22+gout173*d_23+gout174*d_24+gout175*d_25+gout176*d_26+gout177*d_27+gout178*d_28+gout179*d_29);
            // ijkl, il -> jk
            d_0 = dm[(i0+0)+nao*(l0+0)];
            d_1 = dm[(i0+1)+nao*(l0+0)];
            d_2 = dm[(i0+2)+nao*(l0+0)];
            d_3 = dm[(i0+3)+nao*(l0+0)];
            d_4 = dm[(i0+4)+nao*(l0+0)];
            d_5 = dm[(i0+5)+nao*(l0+0)];
            d_6 = dm[(i0+6)+nao*(l0+0)];
            d_7 = dm[(i0+7)+nao*(l0+0)];
            d_8 = dm[(i0+8)+nao*(l0+0)];
            d_9 = dm[(i0+9)+nao*(l0+0)];
            atomicAdd(vk+(j0+0)+nao*(k0+0), gout90*d_0+gout93*d_1+gout96*d_2+gout99*d_3+gout102*d_4+gout105*d_5+gout108*d_6+gout111*d_7+gout114*d_8+gout117*d_9);
            atomicAdd(vk+(j0+0)+nao*(k0+1), gout91*d_0+gout94*d_1+gout97*d_2+gout100*d_3+gout103*d_4+gout106*d_5+gout109*d_6+gout112*d_7+gout115*d_8+gout118*d_9);
            atomicAdd(vk+(j0+0)+nao*(k0+2), gout92*d_0+gout95*d_1+gout98*d_2+gout101*d_3+gout104*d_4+gout107*d_5+gout110*d_6+gout113*d_7+gout116*d_8+gout119*d_9);
            atomicAdd(vk+(j0+0)+nao*(k0+0)+nao2, gout120*d_0+gout123*d_1+gout126*d_2+gout129*d_3+gout132*d_4+gout135*d_5+gout138*d_6+gout141*d_7+gout144*d_8+gout147*d_9);
            atomicAdd(vk+(j0+0)+nao*(k0+1)+nao2, gout121*d_0+gout124*d_1+gout127*d_2+gout130*d_3+gout133*d_4+gout136*d_5+gout139*d_6+gout142*d_7+gout145*d_8+gout148*d_9);
            atomicAdd(vk+(j0+0)+nao*(k0+2)+nao2, gout122*d_0+gout125*d_1+gout128*d_2+gout131*d_3+gout134*d_4+gout137*d_5+gout140*d_6+gout143*d_7+gout146*d_8+gout149*d_9);
            atomicAdd(vk+(j0+0)+nao*(k0+0)+2*nao2, gout150*d_0+gout153*d_1+gout156*d_2+gout159*d_3+gout162*d_4+gout165*d_5+gout168*d_6+gout171*d_7+gout174*d_8+gout177*d_9);
            atomicAdd(vk+(j0+0)+nao*(k0+1)+2*nao2, gout151*d_0+gout154*d_1+gout157*d_2+gout160*d_3+gout163*d_4+gout166*d_5+gout169*d_6+gout172*d_7+gout175*d_8+gout178*d_9);
            atomicAdd(vk+(j0+0)+nao*(k0+2)+2*nao2, gout152*d_0+gout155*d_1+gout158*d_2+gout161*d_3+gout164*d_4+gout167*d_5+gout170*d_6+gout173*d_7+gout176*d_8+gout179*d_9);
            vk += 3*nao2;
        }
        dm += nao2;
    }
}

__global__
static void GINTint2e_ip1_jk_kernel_3100(GINTEnvVars envs, JKMatrix jk,
                                    BasisProdOffsets offsets)
{
    int ntasks_ij = offsets.ntasks_ij;
    int ntasks_kl = offsets.ntasks_kl;
    int task_ij = blockIdx.x * blockDim.x + threadIdx.x;
    int task_kl = blockIdx.y * blockDim.y + threadIdx.y;
    if (task_ij >= ntasks_ij || task_kl >= ntasks_kl) {
        return;
    }
    int bas_ij = offsets.bas_ij + task_ij;
    int bas_kl = offsets.bas_kl + task_kl;
    double norm = envs.fac;
    double omega = envs.omega;
    int *bas_pair2bra = c_bpcache.bas_pair2bra;
    int *bas_pair2ket = c_bpcache.bas_pair2ket;
    int ish = bas_pair2bra[bas_ij];
    int jsh = bas_pair2ket[bas_ij];
    int ksh = bas_pair2bra[bas_kl];
    int lsh = bas_pair2ket[bas_kl];
    int nprim_ij = envs.nprim_ij;
    int nprim_kl = envs.nprim_kl;
    int prim_ij = offsets.primitive_ij + task_ij * nprim_ij;
    int prim_kl = offsets.primitive_kl + task_kl * nprim_kl;

    double* __restrict__ a12 = c_bpcache.a12;
    double* __restrict__ e12 = c_bpcache.e12;
    double* __restrict__ x12 = c_bpcache.x12;
    double* __restrict__ y12 = c_bpcache.y12;
    double* __restrict__ z12 = c_bpcache.z12;
    double * __restrict__ i_exponent = c_bpcache.a1;
    double * __restrict__ j_exponent = c_bpcache.a2;

    int ij, kl;
    int prim_ij0, prim_ij1, prim_kl0, prim_kl1;
    int nbas = c_bpcache.nbas;
    double* __restrict__ bas_x = c_bpcache.bas_coords;
    double* __restrict__ bas_y = bas_x + nbas;
    double* __restrict__ bas_z = bas_y + nbas;

    double gout0 = 0;
    double gout1 = 0;
    double gout2 = 0;
    double gout3 = 0;
    double gout4 = 0;
    double gout5 = 0;
    double gout6 = 0;
    double gout7 = 0;
    double gout8 = 0;
    double gout9 = 0;
    double gout10 = 0;
    double gout11 = 0;
    double gout12 = 0;
    double gout13 = 0;
    double gout14 = 0;
    double gout15 = 0;
    double gout16 = 0;
    double gout17 = 0;
    double gout18 = 0;
    double gout19 = 0;
    double gout20 = 0;
    double gout21 = 0;
    double gout22 = 0;
    double gout23 = 0;
    double gout24 = 0;
    double gout25 = 0;
    double gout26 = 0;
    double gout27 = 0;
    double gout28 = 0;
    double gout29 = 0;
    double gout30 = 0;
    double gout31 = 0;
    double gout32 = 0;
    double gout33 = 0;
    double gout34 = 0;
    double gout35 = 0;
    double gout36 = 0;
    double gout37 = 0;
    double gout38 = 0;
    double gout39 = 0;
    double gout40 = 0;
    double gout41 = 0;
    double gout42 = 0;
    double gout43 = 0;
    double gout44 = 0;
    double gout45 = 0;
    double gout46 = 0;
    double gout47 = 0;
    double gout48 = 0;
    double gout49 = 0;
    double gout50 = 0;
    double gout51 = 0;
    double gout52 = 0;
    double gout53 = 0;
    double gout54 = 0;
    double gout55 = 0;
    double gout56 = 0;
    double gout57 = 0;
    double gout58 = 0;
    double gout59 = 0;
    double gout60 = 0;
    double gout61 = 0;
    double gout62 = 0;
    double gout63 = 0;
    double gout64 = 0;
    double gout65 = 0;
    double gout66 = 0;
    double gout67 = 0;
    double gout68 = 0;
    double gout69 = 0;
    double gout70 = 0;
    double gout71 = 0;
    double gout72 = 0;
    double gout73 = 0;
    double gout74 = 0;
    double gout75 = 0;
    double gout76 = 0;
    double gout77 = 0;
    double gout78 = 0;
    double gout79 = 0;
    double gout80 = 0;
    double gout81 = 0;
    double gout82 = 0;
    double gout83 = 0;
    double gout84 = 0;
    double gout85 = 0;
    double gout86 = 0;
    double gout87 = 0;
    double gout88 = 0;
    double gout89 = 0;
    double gout90 = 0;
    double gout91 = 0;
    double gout92 = 0;
    double gout93 = 0;
    double gout94 = 0;
    double gout95 = 0;
    double gout96 = 0;
    double gout97 = 0;
    double gout98 = 0;
    double gout99 = 0;
    double gout100 = 0;
    double gout101 = 0;
    double gout102 = 0;
    double gout103 = 0;
    double gout104 = 0;
    double gout105 = 0;
    double gout106 = 0;
    double gout107 = 0;
    double gout108 = 0;
    double gout109 = 0;
    double gout110 = 0;
    double gout111 = 0;
    double gout112 = 0;
    double gout113 = 0;
    double gout114 = 0;
    double gout115 = 0;
    double gout116 = 0;
    double gout117 = 0;
    double gout118 = 0;
    double gout119 = 0;
    double gout120 = 0;
    double gout121 = 0;
    double gout122 = 0;
    double gout123 = 0;
    double gout124 = 0;
    double gout125 = 0;
    double gout126 = 0;
    double gout127 = 0;
    double gout128 = 0;
    double gout129 = 0;
    double gout130 = 0;
    double gout131 = 0;
    double gout132 = 0;
    double gout133 = 0;
    double gout134 = 0;
    double gout135 = 0;
    double gout136 = 0;
    double gout137 = 0;
    double gout138 = 0;
    double gout139 = 0;
    double gout140 = 0;
    double gout141 = 0;
    double gout142 = 0;
    double gout143 = 0;
    double gout144 = 0;
    double gout145 = 0;
    double gout146 = 0;
    double gout147 = 0;
    double gout148 = 0;
    double gout149 = 0;
    double gout150 = 0;
    double gout151 = 0;
    double gout152 = 0;
    double gout153 = 0;
    double gout154 = 0;
    double gout155 = 0;
    double gout156 = 0;
    double gout157 = 0;
    double gout158 = 0;
    double gout159 = 0;
    double gout160 = 0;
    double gout161 = 0;
    double gout162 = 0;
    double gout163 = 0;
    double gout164 = 0;
    double gout165 = 0;
    double gout166 = 0;
    double gout167 = 0;
    double gout168 = 0;
    double gout169 = 0;
    double gout170 = 0;
    double gout171 = 0;
    double gout172 = 0;
    double gout173 = 0;
    double gout174 = 0;
    double gout175 = 0;
    double gout176 = 0;
    double gout177 = 0;
    double gout178 = 0;
    double gout179 = 0;

    double xi = bas_x[ish];
    double yi = bas_y[ish];
    double zi = bas_z[ish];
    double ABx = xi - bas_x[jsh];
    double ABy = yi - bas_y[jsh];
    double ABz = zi - bas_z[jsh];


    prim_ij0 = prim_ij;
    prim_ij1 = prim_ij + nprim_ij;
    prim_kl0 = prim_kl;
    prim_kl1 = prim_kl + nprim_kl;
    double rw[6];
    int irys;
    for (ij = prim_ij0; ij < prim_ij1; ++ij) {
        double alpha = i_exponent[ij];
        double beta = j_exponent[ij];
        double aij = a12[ij];
        double eij = e12[ij];
        double xij = x12[ij];
        double yij = y12[ij];
        double zij = z12[ij];
    for (kl = prim_kl0; kl < prim_kl1; ++kl) {
        double akl = a12[kl];
        double ekl = e12[kl];
        double xkl = x12[kl];
        double ykl = y12[kl];
        double zkl = z12[kl];
        double xijxkl = xij - xkl;
        double yijykl = yij - ykl;
        double zijzkl = zij - zkl;
        double aijkl = aij + akl;
        double a1 = aij * akl;
        double a0 = a1 / aijkl;
        double theta = omega > 0.0 ? omega * omega / (omega * omega + a0) : 1.0; 
        a0 *= theta;
        double x = a0 * (xijxkl * xijxkl + yijykl * yijykl + zijzkl * zijzkl);
        double fac = norm * eij * ekl * sqrt(a0 / (a1 * a1 * a1));
        //double fac = norm * eij * ekl / (sqrt(aijkl) * a1);

        GINTrys_root<3>(x, rw);
        GINTscale_u<3>(rw, theta);
      for (irys = 0; irys < 3; ++irys) {
            double weight0 = rw[irys+3] * fac;
            double root0 = rw[irys];
            double u2 = a0 * root0;
            double tmp4 = .5 / (u2 * aijkl + a1);
            double B00 = u2 * tmp4;
            double tmp1 = 2 * B00;
            double B10 = B00 + tmp4 * akl;
            double tmp2 = tmp1 * akl;
            double C00x = xij - xi - tmp2 * xijxkl;
            double C00y = yij - yi - tmp2 * yijykl;
            double C00z = zij - zi - tmp2 * zijzkl;



            double g0 = B10+C00x*C00x;
            double g1 = 3*B10*C00x;
            double g2 = g1+C00x*C00x*C00x;
            double g3 = 3*B10*B10;
            double g4 = 6*B10*C00x*C00x;
            double g5 = g3+g4+C00x*C00x*C00x*C00x;
            double g6 = ABx+C00x;
            double g7 = C00x*g6;
            double g8 = B10+g7;
            double g9 = ABx*g0;
            double g10 = g1+C00x*C00x*C00x+g9;
            double g15 = g3+(C00x*C00x*C00x*g6)+(3*B10*C00x*(ABx+(2*C00x)));
            double g19 = (15*B10*B10*C00x)+(10*B10*C00x*C00x*C00x)+C00x*C00x*C00x*C00x*C00x+(ABx*g5);
            double g20 = B10+g6*g6;
            double g23 = (ABx*ABx*C00x)+g1+C00x*C00x*C00x+(2*ABx*g0);
            double g26 = g3+g4+C00x*C00x*C00x*C00x+(ABx*ABx*g0)+(2*ABx*g2);
            double g28 = 5*B10;
            double g32 = 10*B10;
            double g36 = (6*ABx*B10*B10)+(3*B10*(ABx*ABx+g28)*C00x)+(12*ABx*B10*C00x*C00x)+((ABx*ABx+g32)*C00x*C00x*C00x)+(2*ABx*C00x*C00x*C00x*C00x)+C00x*C00x*C00x*C00x*C00x;
            double g37 = B10+C00y*C00y;
            double g38 = 3*B10*C00y;
            double g39 = g38+C00y*C00y*C00y;
            double g40 = 6*B10*C00y*C00y;
            double g41 = g3+g40+C00y*C00y*C00y*C00y;
            double g42 = ABy+C00y;
            double g44 = B10+(C00y*g42);
            double g46 = g38+C00y*C00y*C00y+(ABy*g37);
            double g51 = g3+(C00y*C00y*C00y*g42)+(3*B10*C00y*(ABy+(2*C00y)));
            double g55 = (15*B10*B10*C00y)+(10*B10*C00y*C00y*C00y)+C00y*C00y*C00y*C00y*C00y+(ABy*g41);
            double g56 = B10+g42*g42;
            double g59 = (ABy*ABy*C00y)+g38+C00y*C00y*C00y+(2*ABy*g37);
            double g62 = g3+g40+C00y*C00y*C00y*C00y+(ABy*ABy*g37)+(2*ABy*g39);
            double g70 = (6*ABy*B10*B10)+(3*B10*(ABy*ABy+g28)*C00y)+(12*ABy*B10*C00y*C00y)+((ABy*ABy+g32)*C00y*C00y*C00y)+(2*ABy*C00y*C00y*C00y*C00y)+C00y*C00y*C00y*C00y*C00y;
            double g71 = B10+C00z*C00z;
            double g72 = 3*B10*C00z;
            double g73 = g72+C00z*C00z*C00z;
            double g74 = 6*B10*C00z*C00z;
            double g75 = g3+g74+C00z*C00z*C00z*C00z;
            double g76 = ABz+C00z;
            double g78 = B10+(C00z*g76);
            double g80 = g72+C00z*C00z*C00z+(ABz*g71);
            double g85 = g3+(C00z*C00z*C00z*g76)+(3*B10*C00z*(ABz+(2*C00z)));
            double g89 = (15*B10*B10*C00z)+(10*B10*C00z*C00z*C00z)+C00z*C00z*C00z*C00z*C00z+(ABz*g75);
            double g90 = B10+g76*g76;
            double g93 = (ABz*ABz*C00z)+g72+C00z*C00z*C00z+(2*ABz*g71);
            double g96 = g3+g74+C00z*C00z*C00z*C00z+(ABz*ABz*g71)+(2*ABz*g73);
            double g104 = (6*ABz*B10*B10)+(3*B10*(ABz*ABz+g28)*C00z)+(12*ABz*B10*C00z*C00z)+((ABz*ABz+g32)*C00z*C00z*C00z)+(2*ABz*C00z*C00z*C00z*C00z)+C00z*C00z*C00z*C00z*C00z;

            gout0 += (-3*g10 + 2*alpha*g19) * weight0;
            gout1 += (-3*g0 + 2*alpha*g5) * (g42) * weight0;
            gout2 += (-3*g0 + 2*alpha*g5) * (g76) * weight0;
            gout3 += (-2*g8 + 2*alpha*g15) * (C00y) * weight0;
            gout4 += (-2*C00x + 2*alpha*g2) * (g44) * weight0;
            gout5 += (-2*C00x + 2*alpha*g2) * (C00y) * (g76) * weight0;
            gout6 += (-2*g8 + 2*alpha*g15) * (C00z) * weight0;
            gout7 += (-2*C00x + 2*alpha*g2) * (g42) * (C00z) * weight0;
            gout8 += (-2*C00x + 2*alpha*g2) * (g78) * weight0;
            gout9 += (-g6 + 2*alpha*g10) * (g37) * weight0;
            gout10 += (-1 + 2*alpha*g0) * (g46) * weight0;
            gout11 += (-1 + 2*alpha*g0) * (g37) * (g76) * weight0;
            gout12 += (-g6 + 2*alpha*g10) * (C00y) * (C00z) * weight0;
            gout13 += (-1 + 2*alpha*g0) * (g44) * (C00z) * weight0;
            gout14 += (-1 + 2*alpha*g0) * (C00y) * (g78) * weight0;
            gout15 += (-g6 + 2*alpha*g10) * (g71) * weight0;
            gout16 += (-1 + 2*alpha*g0) * (g42) * (g71) * weight0;
            gout17 += (-1 + 2*alpha*g0) * (g80) * weight0;
            gout18 += (2*alpha*g8) * (g39) * weight0;
            gout19 += (2*alpha*C00x) * (g51) * weight0;
            gout20 += (2*alpha*C00x) * (g39) * (g76) * weight0;
            gout21 += (2*alpha*g8) * (g37) * (C00z) * weight0;
            gout22 += (2*alpha*C00x) * (g46) * (C00z) * weight0;
            gout23 += (2*alpha*C00x) * (g37) * (g78) * weight0;
            gout24 += (2*alpha*g8) * (C00y) * (g71) * weight0;
            gout25 += (2*alpha*C00x) * (g44) * (g71) * weight0;
            gout26 += (2*alpha*C00x) * (C00y) * (g80) * weight0;
            gout27 += (2*alpha*g8) * (g73) * weight0;
            gout28 += (2*alpha*C00x) * (g42) * (g73) * weight0;
            gout29 += (2*alpha*C00x) * (g85) * weight0;
            gout30 += (g15) * (2*alpha*C00y) * weight0;
            gout31 += (g2) * (2*alpha*g44) * weight0;
            gout32 += (g2) * (2*alpha*C00y) * (g76) * weight0;
            gout33 += (g10) * (-1 + 2*alpha*g37) * weight0;
            gout34 += (g0) * (-g42 + 2*alpha*g46) * weight0;
            gout35 += (g0) * (-1 + 2*alpha*g37) * (g76) * weight0;
            gout36 += (g10) * (2*alpha*C00y) * (C00z) * weight0;
            gout37 += (g0) * (2*alpha*g44) * (C00z) * weight0;
            gout38 += (g0) * (2*alpha*C00y) * (g78) * weight0;
            gout39 += (g8) * (-2*C00y + 2*alpha*g39) * weight0;
            gout40 += (C00x) * (-2*g44 + 2*alpha*g51) * weight0;
            gout41 += (C00x) * (-2*C00y + 2*alpha*g39) * (g76) * weight0;
            gout42 += (g8) * (-1 + 2*alpha*g37) * (C00z) * weight0;
            gout43 += (C00x) * (-g42 + 2*alpha*g46) * (C00z) * weight0;
            gout44 += (C00x) * (-1 + 2*alpha*g37) * (g78) * weight0;
            gout45 += (g8) * (2*alpha*C00y) * (g71) * weight0;
            gout46 += (C00x) * (2*alpha*g44) * (g71) * weight0;
            gout47 += (C00x) * (2*alpha*C00y) * (g80) * weight0;
            gout48 += (g6) * (-3*g37 + 2*alpha*g41) * weight0;
            gout49 += (-3*g46 + 2*alpha*g55) * weight0;
            gout50 += (-3*g37 + 2*alpha*g41) * (g76) * weight0;
            gout51 += (g6) * (-2*C00y + 2*alpha*g39) * (C00z) * weight0;
            gout52 += (-2*g44 + 2*alpha*g51) * (C00z) * weight0;
            gout53 += (-2*C00y + 2*alpha*g39) * (g78) * weight0;
            gout54 += (g6) * (-1 + 2*alpha*g37) * (g71) * weight0;
            gout55 += (-g42 + 2*alpha*g46) * (g71) * weight0;
            gout56 += (-1 + 2*alpha*g37) * (g80) * weight0;
            gout57 += (g6) * (2*alpha*C00y) * (g73) * weight0;
            gout58 += (2*alpha*g44) * (g73) * weight0;
            gout59 += (2*alpha*C00y) * (g85) * weight0;
            gout60 += (g15) * (2*alpha*C00z) * weight0;
            gout61 += (g2) * (g42) * (2*alpha*C00z) * weight0;
            gout62 += (g2) * (2*alpha*g78) * weight0;
            gout63 += (g10) * (C00y) * (2*alpha*C00z) * weight0;
            gout64 += (g0) * (g44) * (2*alpha*C00z) * weight0;
            gout65 += (g0) * (C00y) * (2*alpha*g78) * weight0;
            gout66 += (g10) * (-1 + 2*alpha*g71) * weight0;
            gout67 += (g0) * (g42) * (-1 + 2*alpha*g71) * weight0;
            gout68 += (g0) * (-g76 + 2*alpha*g80) * weight0;
            gout69 += (g8) * (g37) * (2*alpha*C00z) * weight0;
            gout70 += (C00x) * (g46) * (2*alpha*C00z) * weight0;
            gout71 += (C00x) * (g37) * (2*alpha*g78) * weight0;
            gout72 += (g8) * (C00y) * (-1 + 2*alpha*g71) * weight0;
            gout73 += (C00x) * (g44) * (-1 + 2*alpha*g71) * weight0;
            gout74 += (C00x) * (C00y) * (-g76 + 2*alpha*g80) * weight0;
            gout75 += (g8) * (-2*C00z + 2*alpha*g73) * weight0;
            gout76 += (C00x) * (g42) * (-2*C00z + 2*alpha*g73) * weight0;
            gout77 += (C00x) * (-2*g78 + 2*alpha*g85) * weight0;
            gout78 += (g6) * (g39) * (2*alpha*C00z) * weight0;
            gout79 += (g51) * (2*alpha*C00z) * weight0;
            gout80 += (g39) * (2*alpha*g78) * weight0;
            gout81 += (g6) * (g37) * (-1 + 2*alpha*g71) * weight0;
            gout82 += (g46) * (-1 + 2*alpha*g71) * weight0;
            gout83 += (g37) * (-g76 + 2*alpha*g80) * weight0;
            gout84 += (g6) * (C00y) * (-2*C00z + 2*alpha*g73) * weight0;
            gout85 += (g44) * (-2*C00z + 2*alpha*g73) * weight0;
            gout86 += (C00y) * (-2*g78 + 2*alpha*g85) * weight0;
            gout87 += (g6) * (-3*g71 + 2*alpha*g75) * weight0;
            gout88 += (g42) * (-3*g71 + 2*alpha*g75) * weight0;
            gout89 += (-3*g80 + 2*alpha*g89) * weight0;
            gout90 += (-g2 + 2*beta*g36) * weight0;
            gout91 += (2*beta*g15) * (g42) * weight0;
            gout92 += (2*beta*g15) * (g76) * weight0;
            gout93 += (-g0 + 2*beta*g26) * (C00y) * weight0;
            gout94 += (2*beta*g10) * (g44) * weight0;
            gout95 += (2*beta*g10) * (C00y) * (g76) * weight0;
            gout96 += (-g0 + 2*beta*g26) * (C00z) * weight0;
            gout97 += (2*beta*g10) * (g42) * (C00z) * weight0;
            gout98 += (2*beta*g10) * (g78) * weight0;
            gout99 += (-C00x + 2*beta*g23) * (g37) * weight0;
            gout100 += (2*beta*g8) * (g46) * weight0;
            gout101 += (2*beta*g8) * (g37) * (g76) * weight0;
            gout102 += (-C00x + 2*beta*g23) * (C00y) * (C00z) * weight0;
            gout103 += (2*beta*g8) * (g44) * (C00z) * weight0;
            gout104 += (2*beta*g8) * (C00y) * (g78) * weight0;
            gout105 += (-C00x + 2*beta*g23) * (g71) * weight0;
            gout106 += (2*beta*g8) * (g42) * (g71) * weight0;
            gout107 += (2*beta*g8) * (g80) * weight0;
            gout108 += (-1 + 2*beta*g20) * (g39) * weight0;
            gout109 += (2*beta*g6) * (g51) * weight0;
            gout110 += (2*beta*g6) * (g39) * (g76) * weight0;
            gout111 += (-1 + 2*beta*g20) * (g37) * (C00z) * weight0;
            gout112 += (2*beta*g6) * (g46) * (C00z) * weight0;
            gout113 += (2*beta*g6) * (g37) * (g78) * weight0;
            gout114 += (-1 + 2*beta*g20) * (C00y) * (g71) * weight0;
            gout115 += (2*beta*g6) * (g44) * (g71) * weight0;
            gout116 += (2*beta*g6) * (C00y) * (g80) * weight0;
            gout117 += (-1 + 2*beta*g20) * (g73) * weight0;
            gout118 += (2*beta*g6) * (g42) * (g73) * weight0;
            gout119 += (2*beta*g6) * (g85) * weight0;
            gout120 += (g15) * (2*beta*g42) * weight0;
            gout121 += (g2) * (-1 + 2*beta*g56) * weight0;
            gout122 += (g2) * (2*beta*g42) * (g76) * weight0;
            gout123 += (g10) * (2*beta*g44) * weight0;
            gout124 += (g0) * (-C00y + 2*beta*g59) * weight0;
            gout125 += (g0) * (2*beta*g44) * (g76) * weight0;
            gout126 += (g10) * (2*beta*g42) * (C00z) * weight0;
            gout127 += (g0) * (-1 + 2*beta*g56) * (C00z) * weight0;
            gout128 += (g0) * (2*beta*g42) * (g78) * weight0;
            gout129 += (g8) * (2*beta*g46) * weight0;
            gout130 += (C00x) * (-g37 + 2*beta*g62) * weight0;
            gout131 += (C00x) * (2*beta*g46) * (g76) * weight0;
            gout132 += (g8) * (2*beta*g44) * (C00z) * weight0;
            gout133 += (C00x) * (-C00y + 2*beta*g59) * (C00z) * weight0;
            gout134 += (C00x) * (2*beta*g44) * (g78) * weight0;
            gout135 += (g8) * (2*beta*g42) * (g71) * weight0;
            gout136 += (C00x) * (-1 + 2*beta*g56) * (g71) * weight0;
            gout137 += (C00x) * (2*beta*g42) * (g80) * weight0;
            gout138 += (g6) * (2*beta*g51) * weight0;
            gout139 += (-g39 + 2*beta*g70) * weight0;
            gout140 += (2*beta*g51) * (g76) * weight0;
            gout141 += (g6) * (2*beta*g46) * (C00z) * weight0;
            gout142 += (-g37 + 2*beta*g62) * (C00z) * weight0;
            gout143 += (2*beta*g46) * (g78) * weight0;
            gout144 += (g6) * (2*beta*g44) * (g71) * weight0;
            gout145 += (-C00y + 2*beta*g59) * (g71) * weight0;
            gout146 += (2*beta*g44) * (g80) * weight0;
            gout147 += (g6) * (2*beta*g42) * (g73) * weight0;
            gout148 += (-1 + 2*beta*g56) * (g73) * weight0;
            gout149 += (2*beta*g42) * (g85) * weight0;
            gout150 += (g15) * (2*beta*g76) * weight0;
            gout151 += (g2) * (g42) * (2*beta*g76) * weight0;
            gout152 += (g2) * (-1 + 2*beta*g90) * weight0;
            gout153 += (g10) * (C00y) * (2*beta*g76) * weight0;
            gout154 += (g0) * (g44) * (2*beta*g76) * weight0;
            gout155 += (g0) * (C00y) * (-1 + 2*beta*g90) * weight0;
            gout156 += (g10) * (2*beta*g78) * weight0;
            gout157 += (g0) * (g42) * (2*beta*g78) * weight0;
            gout158 += (g0) * (-C00z + 2*beta*g93) * weight0;
            gout159 += (g8) * (g37) * (2*beta*g76) * weight0;
            gout160 += (C00x) * (g46) * (2*beta*g76) * weight0;
            gout161 += (C00x) * (g37) * (-1 + 2*beta*g90) * weight0;
            gout162 += (g8) * (C00y) * (2*beta*g78) * weight0;
            gout163 += (C00x) * (g44) * (2*beta*g78) * weight0;
            gout164 += (C00x) * (C00y) * (-C00z + 2*beta*g93) * weight0;
            gout165 += (g8) * (2*beta*g80) * weight0;
            gout166 += (C00x) * (g42) * (2*beta*g80) * weight0;
            gout167 += (C00x) * (-g71 + 2*beta*g96) * weight0;
            gout168 += (g6) * (g39) * (2*beta*g76) * weight0;
            gout169 += (g51) * (2*beta*g76) * weight0;
            gout170 += (g39) * (-1 + 2*beta*g90) * weight0;
            gout171 += (g6) * (g37) * (2*beta*g78) * weight0;
            gout172 += (g46) * (2*beta*g78) * weight0;
            gout173 += (g37) * (-C00z + 2*beta*g93) * weight0;
            gout174 += (g6) * (C00y) * (2*beta*g80) * weight0;
            gout175 += (g44) * (2*beta*g80) * weight0;
            gout176 += (C00y) * (-g71 + 2*beta*g96) * weight0;
            gout177 += (g6) * (2*beta*g85) * weight0;
            gout178 += (g42) * (2*beta*g85) * weight0;
            gout179 += (-g73 + 2*beta*g104) * weight0;
        }
    } }

    int *ao_loc = c_bpcache.ao_loc;
    int i0 = ao_loc[ish];
    int j0 = ao_loc[jsh];
    int k0 = ao_loc[ksh];
    int l0 = ao_loc[lsh];
    int n_dm = jk.n_dm;
    int nao = jk.nao;
    size_t nao2 = nao * nao;
    double* __restrict__ dm = jk.dm;
    double *vj = jk.vj;
    double *vk = jk.vk;
    double d_0, d_1, d_2, d_3, d_4, d_5, d_6, d_7, d_8, d_9;

    for (int i_dm = 0; i_dm < n_dm; ++i_dm) {
        if (vj != NULL) {
            d_0 = dm[(k0+0)+nao*(l0+0)];
            atomicAdd(vj+(i0+0)+nao*(j0+0), gout0*d_0);
            atomicAdd(vj+(i0+0)+nao*(j0+1), gout1*d_0);
            atomicAdd(vj+(i0+0)+nao*(j0+2), gout2*d_0);
            atomicAdd(vj+(i0+1)+nao*(j0+0), gout3*d_0);
            atomicAdd(vj+(i0+1)+nao*(j0+1), gout4*d_0);
            atomicAdd(vj+(i0+1)+nao*(j0+2), gout5*d_0);
            atomicAdd(vj+(i0+2)+nao*(j0+0), gout6*d_0);
            atomicAdd(vj+(i0+2)+nao*(j0+1), gout7*d_0);
            atomicAdd(vj+(i0+2)+nao*(j0+2), gout8*d_0);
            atomicAdd(vj+(i0+3)+nao*(j0+0), gout9*d_0);
            atomicAdd(vj+(i0+3)+nao*(j0+1), gout10*d_0);
            atomicAdd(vj+(i0+3)+nao*(j0+2), gout11*d_0);
            atomicAdd(vj+(i0+4)+nao*(j0+0), gout12*d_0);
            atomicAdd(vj+(i0+4)+nao*(j0+1), gout13*d_0);
            atomicAdd(vj+(i0+4)+nao*(j0+2), gout14*d_0);
            atomicAdd(vj+(i0+5)+nao*(j0+0), gout15*d_0);
            atomicAdd(vj+(i0+5)+nao*(j0+1), gout16*d_0);
            atomicAdd(vj+(i0+5)+nao*(j0+2), gout17*d_0);
            atomicAdd(vj+(i0+6)+nao*(j0+0), gout18*d_0);
            atomicAdd(vj+(i0+6)+nao*(j0+1), gout19*d_0);
            atomicAdd(vj+(i0+6)+nao*(j0+2), gout20*d_0);
            atomicAdd(vj+(i0+7)+nao*(j0+0), gout21*d_0);
            atomicAdd(vj+(i0+7)+nao*(j0+1), gout22*d_0);
            atomicAdd(vj+(i0+7)+nao*(j0+2), gout23*d_0);
            atomicAdd(vj+(i0+8)+nao*(j0+0), gout24*d_0);
            atomicAdd(vj+(i0+8)+nao*(j0+1), gout25*d_0);
            atomicAdd(vj+(i0+8)+nao*(j0+2), gout26*d_0);
            atomicAdd(vj+(i0+9)+nao*(j0+0), gout27*d_0);
            atomicAdd(vj+(i0+9)+nao*(j0+1), gout28*d_0);
            atomicAdd(vj+(i0+9)+nao*(j0+2), gout29*d_0);
            atomicAdd(vj+(i0+0)+nao*(j0+0)+nao2, gout30*d_0);
            atomicAdd(vj+(i0+0)+nao*(j0+1)+nao2, gout31*d_0);
            atomicAdd(vj+(i0+0)+nao*(j0+2)+nao2, gout32*d_0);
            atomicAdd(vj+(i0+1)+nao*(j0+0)+nao2, gout33*d_0);
            atomicAdd(vj+(i0+1)+nao*(j0+1)+nao2, gout34*d_0);
            atomicAdd(vj+(i0+1)+nao*(j0+2)+nao2, gout35*d_0);
            atomicAdd(vj+(i0+2)+nao*(j0+0)+nao2, gout36*d_0);
            atomicAdd(vj+(i0+2)+nao*(j0+1)+nao2, gout37*d_0);
            atomicAdd(vj+(i0+2)+nao*(j0+2)+nao2, gout38*d_0);
            atomicAdd(vj+(i0+3)+nao*(j0+0)+nao2, gout39*d_0);
            atomicAdd(vj+(i0+3)+nao*(j0+1)+nao2, gout40*d_0);
            atomicAdd(vj+(i0+3)+nao*(j0+2)+nao2, gout41*d_0);
            atomicAdd(vj+(i0+4)+nao*(j0+0)+nao2, gout42*d_0);
            atomicAdd(vj+(i0+4)+nao*(j0+1)+nao2, gout43*d_0);
            atomicAdd(vj+(i0+4)+nao*(j0+2)+nao2, gout44*d_0);
            atomicAdd(vj+(i0+5)+nao*(j0+0)+nao2, gout45*d_0);
            atomicAdd(vj+(i0+5)+nao*(j0+1)+nao2, gout46*d_0);
            atomicAdd(vj+(i0+5)+nao*(j0+2)+nao2, gout47*d_0);
            atomicAdd(vj+(i0+6)+nao*(j0+0)+nao2, gout48*d_0);
            atomicAdd(vj+(i0+6)+nao*(j0+1)+nao2, gout49*d_0);
            atomicAdd(vj+(i0+6)+nao*(j0+2)+nao2, gout50*d_0);
            atomicAdd(vj+(i0+7)+nao*(j0+0)+nao2, gout51*d_0);
            atomicAdd(vj+(i0+7)+nao*(j0+1)+nao2, gout52*d_0);
            atomicAdd(vj+(i0+7)+nao*(j0+2)+nao2, gout53*d_0);
            atomicAdd(vj+(i0+8)+nao*(j0+0)+nao2, gout54*d_0);
            atomicAdd(vj+(i0+8)+nao*(j0+1)+nao2, gout55*d_0);
            atomicAdd(vj+(i0+8)+nao*(j0+2)+nao2, gout56*d_0);
            atomicAdd(vj+(i0+9)+nao*(j0+0)+nao2, gout57*d_0);
            atomicAdd(vj+(i0+9)+nao*(j0+1)+nao2, gout58*d_0);
            atomicAdd(vj+(i0+9)+nao*(j0+2)+nao2, gout59*d_0);
            atomicAdd(vj+(i0+0)+nao*(j0+0)+2*nao2, gout60*d_0);
            atomicAdd(vj+(i0+0)+nao*(j0+1)+2*nao2, gout61*d_0);
            atomicAdd(vj+(i0+0)+nao*(j0+2)+2*nao2, gout62*d_0);
            atomicAdd(vj+(i0+1)+nao*(j0+0)+2*nao2, gout63*d_0);
            atomicAdd(vj+(i0+1)+nao*(j0+1)+2*nao2, gout64*d_0);
            atomicAdd(vj+(i0+1)+nao*(j0+2)+2*nao2, gout65*d_0);
            atomicAdd(vj+(i0+2)+nao*(j0+0)+2*nao2, gout66*d_0);
            atomicAdd(vj+(i0+2)+nao*(j0+1)+2*nao2, gout67*d_0);
            atomicAdd(vj+(i0+2)+nao*(j0+2)+2*nao2, gout68*d_0);
            atomicAdd(vj+(i0+3)+nao*(j0+0)+2*nao2, gout69*d_0);
            atomicAdd(vj+(i0+3)+nao*(j0+1)+2*nao2, gout70*d_0);
            atomicAdd(vj+(i0+3)+nao*(j0+2)+2*nao2, gout71*d_0);
            atomicAdd(vj+(i0+4)+nao*(j0+0)+2*nao2, gout72*d_0);
            atomicAdd(vj+(i0+4)+nao*(j0+1)+2*nao2, gout73*d_0);
            atomicAdd(vj+(i0+4)+nao*(j0+2)+2*nao2, gout74*d_0);
            atomicAdd(vj+(i0+5)+nao*(j0+0)+2*nao2, gout75*d_0);
            atomicAdd(vj+(i0+5)+nao*(j0+1)+2*nao2, gout76*d_0);
            atomicAdd(vj+(i0+5)+nao*(j0+2)+2*nao2, gout77*d_0);
            atomicAdd(vj+(i0+6)+nao*(j0+0)+2*nao2, gout78*d_0);
            atomicAdd(vj+(i0+6)+nao*(j0+1)+2*nao2, gout79*d_0);
            atomicAdd(vj+(i0+6)+nao*(j0+2)+2*nao2, gout80*d_0);
            atomicAdd(vj+(i0+7)+nao*(j0+0)+2*nao2, gout81*d_0);
            atomicAdd(vj+(i0+7)+nao*(j0+1)+2*nao2, gout82*d_0);
            atomicAdd(vj+(i0+7)+nao*(j0+2)+2*nao2, gout83*d_0);
            atomicAdd(vj+(i0+8)+nao*(j0+0)+2*nao2, gout84*d_0);
            atomicAdd(vj+(i0+8)+nao*(j0+1)+2*nao2, gout85*d_0);
            atomicAdd(vj+(i0+8)+nao*(j0+2)+2*nao2, gout86*d_0);
            atomicAdd(vj+(i0+9)+nao*(j0+0)+2*nao2, gout87*d_0);
            atomicAdd(vj+(i0+9)+nao*(j0+1)+2*nao2, gout88*d_0);
            atomicAdd(vj+(i0+9)+nao*(j0+2)+2*nao2, gout89*d_0);
            atomicAdd(vj+nao*(i0+0)+(j0+0), gout90*d_0);
            atomicAdd(vj+nao*(i0+0)+(j0+1), gout91*d_0);
            atomicAdd(vj+nao*(i0+0)+(j0+2), gout92*d_0);
            atomicAdd(vj+nao*(i0+1)+(j0+0), gout93*d_0);
            atomicAdd(vj+nao*(i0+1)+(j0+1), gout94*d_0);
            atomicAdd(vj+nao*(i0+1)+(j0+2), gout95*d_0);
            atomicAdd(vj+nao*(i0+2)+(j0+0), gout96*d_0);
            atomicAdd(vj+nao*(i0+2)+(j0+1), gout97*d_0);
            atomicAdd(vj+nao*(i0+2)+(j0+2), gout98*d_0);
            atomicAdd(vj+nao*(i0+3)+(j0+0), gout99*d_0);
            atomicAdd(vj+nao*(i0+3)+(j0+1), gout100*d_0);
            atomicAdd(vj+nao*(i0+3)+(j0+2), gout101*d_0);
            atomicAdd(vj+nao*(i0+4)+(j0+0), gout102*d_0);
            atomicAdd(vj+nao*(i0+4)+(j0+1), gout103*d_0);
            atomicAdd(vj+nao*(i0+4)+(j0+2), gout104*d_0);
            atomicAdd(vj+nao*(i0+5)+(j0+0), gout105*d_0);
            atomicAdd(vj+nao*(i0+5)+(j0+1), gout106*d_0);
            atomicAdd(vj+nao*(i0+5)+(j0+2), gout107*d_0);
            atomicAdd(vj+nao*(i0+6)+(j0+0), gout108*d_0);
            atomicAdd(vj+nao*(i0+6)+(j0+1), gout109*d_0);
            atomicAdd(vj+nao*(i0+6)+(j0+2), gout110*d_0);
            atomicAdd(vj+nao*(i0+7)+(j0+0), gout111*d_0);
            atomicAdd(vj+nao*(i0+7)+(j0+1), gout112*d_0);
            atomicAdd(vj+nao*(i0+7)+(j0+2), gout113*d_0);
            atomicAdd(vj+nao*(i0+8)+(j0+0), gout114*d_0);
            atomicAdd(vj+nao*(i0+8)+(j0+1), gout115*d_0);
            atomicAdd(vj+nao*(i0+8)+(j0+2), gout116*d_0);
            atomicAdd(vj+nao*(i0+9)+(j0+0), gout117*d_0);
            atomicAdd(vj+nao*(i0+9)+(j0+1), gout118*d_0);
            atomicAdd(vj+nao*(i0+9)+(j0+2), gout119*d_0);
            atomicAdd(vj+nao*(i0+0)+(j0+0)+nao2, gout120*d_0);
            atomicAdd(vj+nao*(i0+0)+(j0+1)+nao2, gout121*d_0);
            atomicAdd(vj+nao*(i0+0)+(j0+2)+nao2, gout122*d_0);
            atomicAdd(vj+nao*(i0+1)+(j0+0)+nao2, gout123*d_0);
            atomicAdd(vj+nao*(i0+1)+(j0+1)+nao2, gout124*d_0);
            atomicAdd(vj+nao*(i0+1)+(j0+2)+nao2, gout125*d_0);
            atomicAdd(vj+nao*(i0+2)+(j0+0)+nao2, gout126*d_0);
            atomicAdd(vj+nao*(i0+2)+(j0+1)+nao2, gout127*d_0);
            atomicAdd(vj+nao*(i0+2)+(j0+2)+nao2, gout128*d_0);
            atomicAdd(vj+nao*(i0+3)+(j0+0)+nao2, gout129*d_0);
            atomicAdd(vj+nao*(i0+3)+(j0+1)+nao2, gout130*d_0);
            atomicAdd(vj+nao*(i0+3)+(j0+2)+nao2, gout131*d_0);
            atomicAdd(vj+nao*(i0+4)+(j0+0)+nao2, gout132*d_0);
            atomicAdd(vj+nao*(i0+4)+(j0+1)+nao2, gout133*d_0);
            atomicAdd(vj+nao*(i0+4)+(j0+2)+nao2, gout134*d_0);
            atomicAdd(vj+nao*(i0+5)+(j0+0)+nao2, gout135*d_0);
            atomicAdd(vj+nao*(i0+5)+(j0+1)+nao2, gout136*d_0);
            atomicAdd(vj+nao*(i0+5)+(j0+2)+nao2, gout137*d_0);
            atomicAdd(vj+nao*(i0+6)+(j0+0)+nao2, gout138*d_0);
            atomicAdd(vj+nao*(i0+6)+(j0+1)+nao2, gout139*d_0);
            atomicAdd(vj+nao*(i0+6)+(j0+2)+nao2, gout140*d_0);
            atomicAdd(vj+nao*(i0+7)+(j0+0)+nao2, gout141*d_0);
            atomicAdd(vj+nao*(i0+7)+(j0+1)+nao2, gout142*d_0);
            atomicAdd(vj+nao*(i0+7)+(j0+2)+nao2, gout143*d_0);
            atomicAdd(vj+nao*(i0+8)+(j0+0)+nao2, gout144*d_0);
            atomicAdd(vj+nao*(i0+8)+(j0+1)+nao2, gout145*d_0);
            atomicAdd(vj+nao*(i0+8)+(j0+2)+nao2, gout146*d_0);
            atomicAdd(vj+nao*(i0+9)+(j0+0)+nao2, gout147*d_0);
            atomicAdd(vj+nao*(i0+9)+(j0+1)+nao2, gout148*d_0);
            atomicAdd(vj+nao*(i0+9)+(j0+2)+nao2, gout149*d_0);
            atomicAdd(vj+nao*(i0+0)+(j0+0)+2*nao2, gout150*d_0);
            atomicAdd(vj+nao*(i0+0)+(j0+1)+2*nao2, gout151*d_0);
            atomicAdd(vj+nao*(i0+0)+(j0+2)+2*nao2, gout152*d_0);
            atomicAdd(vj+nao*(i0+1)+(j0+0)+2*nao2, gout153*d_0);
            atomicAdd(vj+nao*(i0+1)+(j0+1)+2*nao2, gout154*d_0);
            atomicAdd(vj+nao*(i0+1)+(j0+2)+2*nao2, gout155*d_0);
            atomicAdd(vj+nao*(i0+2)+(j0+0)+2*nao2, gout156*d_0);
            atomicAdd(vj+nao*(i0+2)+(j0+1)+2*nao2, gout157*d_0);
            atomicAdd(vj+nao*(i0+2)+(j0+2)+2*nao2, gout158*d_0);
            atomicAdd(vj+nao*(i0+3)+(j0+0)+2*nao2, gout159*d_0);
            atomicAdd(vj+nao*(i0+3)+(j0+1)+2*nao2, gout160*d_0);
            atomicAdd(vj+nao*(i0+3)+(j0+2)+2*nao2, gout161*d_0);
            atomicAdd(vj+nao*(i0+4)+(j0+0)+2*nao2, gout162*d_0);
            atomicAdd(vj+nao*(i0+4)+(j0+1)+2*nao2, gout163*d_0);
            atomicAdd(vj+nao*(i0+4)+(j0+2)+2*nao2, gout164*d_0);
            atomicAdd(vj+nao*(i0+5)+(j0+0)+2*nao2, gout165*d_0);
            atomicAdd(vj+nao*(i0+5)+(j0+1)+2*nao2, gout166*d_0);
            atomicAdd(vj+nao*(i0+5)+(j0+2)+2*nao2, gout167*d_0);
            atomicAdd(vj+nao*(i0+6)+(j0+0)+2*nao2, gout168*d_0);
            atomicAdd(vj+nao*(i0+6)+(j0+1)+2*nao2, gout169*d_0);
            atomicAdd(vj+nao*(i0+6)+(j0+2)+2*nao2, gout170*d_0);
            atomicAdd(vj+nao*(i0+7)+(j0+0)+2*nao2, gout171*d_0);
            atomicAdd(vj+nao*(i0+7)+(j0+1)+2*nao2, gout172*d_0);
            atomicAdd(vj+nao*(i0+7)+(j0+2)+2*nao2, gout173*d_0);
            atomicAdd(vj+nao*(i0+8)+(j0+0)+2*nao2, gout174*d_0);
            atomicAdd(vj+nao*(i0+8)+(j0+1)+2*nao2, gout175*d_0);
            atomicAdd(vj+nao*(i0+8)+(j0+2)+2*nao2, gout176*d_0);
            atomicAdd(vj+nao*(i0+9)+(j0+0)+2*nao2, gout177*d_0);
            atomicAdd(vj+nao*(i0+9)+(j0+1)+2*nao2, gout178*d_0);
            atomicAdd(vj+nao*(i0+9)+(j0+2)+2*nao2, gout179*d_0);
            vj += 3*nao2;
        }
        if (vk != NULL) {
            // ijkl, jk -> il
            d_0 = dm[(j0+0)+nao*(k0+0)];
            d_1 = dm[(j0+1)+nao*(k0+0)];
            d_2 = dm[(j0+2)+nao*(k0+0)];
            atomicAdd(vk+(i0+0)+nao*(l0+0), gout0*d_0+gout1*d_1+gout2*d_2);
            atomicAdd(vk+(i0+1)+nao*(l0+0), gout3*d_0+gout4*d_1+gout5*d_2);
            atomicAdd(vk+(i0+2)+nao*(l0+0), gout6*d_0+gout7*d_1+gout8*d_2);
            atomicAdd(vk+(i0+3)+nao*(l0+0), gout9*d_0+gout10*d_1+gout11*d_2);
            atomicAdd(vk+(i0+4)+nao*(l0+0), gout12*d_0+gout13*d_1+gout14*d_2);
            atomicAdd(vk+(i0+5)+nao*(l0+0), gout15*d_0+gout16*d_1+gout17*d_2);
            atomicAdd(vk+(i0+6)+nao*(l0+0), gout18*d_0+gout19*d_1+gout20*d_2);
            atomicAdd(vk+(i0+7)+nao*(l0+0), gout21*d_0+gout22*d_1+gout23*d_2);
            atomicAdd(vk+(i0+8)+nao*(l0+0), gout24*d_0+gout25*d_1+gout26*d_2);
            atomicAdd(vk+(i0+9)+nao*(l0+0), gout27*d_0+gout28*d_1+gout29*d_2);
            atomicAdd(vk+(i0+0)+nao*(l0+0)+nao2, gout30*d_0+gout31*d_1+gout32*d_2);
            atomicAdd(vk+(i0+1)+nao*(l0+0)+nao2, gout33*d_0+gout34*d_1+gout35*d_2);
            atomicAdd(vk+(i0+2)+nao*(l0+0)+nao2, gout36*d_0+gout37*d_1+gout38*d_2);
            atomicAdd(vk+(i0+3)+nao*(l0+0)+nao2, gout39*d_0+gout40*d_1+gout41*d_2);
            atomicAdd(vk+(i0+4)+nao*(l0+0)+nao2, gout42*d_0+gout43*d_1+gout44*d_2);
            atomicAdd(vk+(i0+5)+nao*(l0+0)+nao2, gout45*d_0+gout46*d_1+gout47*d_2);
            atomicAdd(vk+(i0+6)+nao*(l0+0)+nao2, gout48*d_0+gout49*d_1+gout50*d_2);
            atomicAdd(vk+(i0+7)+nao*(l0+0)+nao2, gout51*d_0+gout52*d_1+gout53*d_2);
            atomicAdd(vk+(i0+8)+nao*(l0+0)+nao2, gout54*d_0+gout55*d_1+gout56*d_2);
            atomicAdd(vk+(i0+9)+nao*(l0+0)+nao2, gout57*d_0+gout58*d_1+gout59*d_2);
            atomicAdd(vk+(i0+0)+nao*(l0+0)+2*nao2, gout60*d_0+gout61*d_1+gout62*d_2);
            atomicAdd(vk+(i0+1)+nao*(l0+0)+2*nao2, gout63*d_0+gout64*d_1+gout65*d_2);
            atomicAdd(vk+(i0+2)+nao*(l0+0)+2*nao2, gout66*d_0+gout67*d_1+gout68*d_2);
            atomicAdd(vk+(i0+3)+nao*(l0+0)+2*nao2, gout69*d_0+gout70*d_1+gout71*d_2);
            atomicAdd(vk+(i0+4)+nao*(l0+0)+2*nao2, gout72*d_0+gout73*d_1+gout74*d_2);
            atomicAdd(vk+(i0+5)+nao*(l0+0)+2*nao2, gout75*d_0+gout76*d_1+gout77*d_2);
            atomicAdd(vk+(i0+6)+nao*(l0+0)+2*nao2, gout78*d_0+gout79*d_1+gout80*d_2);
            atomicAdd(vk+(i0+7)+nao*(l0+0)+2*nao2, gout81*d_0+gout82*d_1+gout83*d_2);
            atomicAdd(vk+(i0+8)+nao*(l0+0)+2*nao2, gout84*d_0+gout85*d_1+gout86*d_2);
            atomicAdd(vk+(i0+9)+nao*(l0+0)+2*nao2, gout87*d_0+gout88*d_1+gout89*d_2);
            // ijkl, jl -> ik
            d_0 = dm[(j0+0)+nao*(l0+0)];
            d_1 = dm[(j0+1)+nao*(l0+0)];
            d_2 = dm[(j0+2)+nao*(l0+0)];
            atomicAdd(vk+(i0+0)+nao*(k0+0), gout0*d_0+gout1*d_1+gout2*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+0), gout3*d_0+gout4*d_1+gout5*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+0), gout6*d_0+gout7*d_1+gout8*d_2);
            atomicAdd(vk+(i0+3)+nao*(k0+0), gout9*d_0+gout10*d_1+gout11*d_2);
            atomicAdd(vk+(i0+4)+nao*(k0+0), gout12*d_0+gout13*d_1+gout14*d_2);
            atomicAdd(vk+(i0+5)+nao*(k0+0), gout15*d_0+gout16*d_1+gout17*d_2);
            atomicAdd(vk+(i0+6)+nao*(k0+0), gout18*d_0+gout19*d_1+gout20*d_2);
            atomicAdd(vk+(i0+7)+nao*(k0+0), gout21*d_0+gout22*d_1+gout23*d_2);
            atomicAdd(vk+(i0+8)+nao*(k0+0), gout24*d_0+gout25*d_1+gout26*d_2);
            atomicAdd(vk+(i0+9)+nao*(k0+0), gout27*d_0+gout28*d_1+gout29*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+0)+nao2, gout30*d_0+gout31*d_1+gout32*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+0)+nao2, gout33*d_0+gout34*d_1+gout35*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+0)+nao2, gout36*d_0+gout37*d_1+gout38*d_2);
            atomicAdd(vk+(i0+3)+nao*(k0+0)+nao2, gout39*d_0+gout40*d_1+gout41*d_2);
            atomicAdd(vk+(i0+4)+nao*(k0+0)+nao2, gout42*d_0+gout43*d_1+gout44*d_2);
            atomicAdd(vk+(i0+5)+nao*(k0+0)+nao2, gout45*d_0+gout46*d_1+gout47*d_2);
            atomicAdd(vk+(i0+6)+nao*(k0+0)+nao2, gout48*d_0+gout49*d_1+gout50*d_2);
            atomicAdd(vk+(i0+7)+nao*(k0+0)+nao2, gout51*d_0+gout52*d_1+gout53*d_2);
            atomicAdd(vk+(i0+8)+nao*(k0+0)+nao2, gout54*d_0+gout55*d_1+gout56*d_2);
            atomicAdd(vk+(i0+9)+nao*(k0+0)+nao2, gout57*d_0+gout58*d_1+gout59*d_2);
            atomicAdd(vk+(i0+0)+nao*(k0+0)+2*nao2, gout60*d_0+gout61*d_1+gout62*d_2);
            atomicAdd(vk+(i0+1)+nao*(k0+0)+2*nao2, gout63*d_0+gout64*d_1+gout65*d_2);
            atomicAdd(vk+(i0+2)+nao*(k0+0)+2*nao2, gout66*d_0+gout67*d_1+gout68*d_2);
            atomicAdd(vk+(i0+3)+nao*(k0+0)+2*nao2, gout69*d_0+gout70*d_1+gout71*d_2);
            atomicAdd(vk+(i0+4)+nao*(k0+0)+2*nao2, gout72*d_0+gout73*d_1+gout74*d_2);
            atomicAdd(vk+(i0+5)+nao*(k0+0)+2*nao2, gout75*d_0+gout76*d_1+gout77*d_2);
            atomicAdd(vk+(i0+6)+nao*(k0+0)+2*nao2, gout78*d_0+gout79*d_1+gout80*d_2);
            atomicAdd(vk+(i0+7)+nao*(k0+0)+2*nao2, gout81*d_0+gout82*d_1+gout83*d_2);
            atomicAdd(vk+(i0+8)+nao*(k0+0)+2*nao2, gout84*d_0+gout85*d_1+gout86*d_2);
            atomicAdd(vk+(i0+9)+nao*(k0+0)+2*nao2, gout87*d_0+gout88*d_1+gout89*d_2);
            // ijkl, ik -> jl
            d_0 = dm[(i0+0)+nao*(k0+0)];
            d_1 = dm[(i0+1)+nao*(k0+0)];
            d_2 = dm[(i0+2)+nao*(k0+0)];
            d_3 = dm[(i0+3)+nao*(k0+0)];
            d_4 = dm[(i0+4)+nao*(k0+0)];
            d_5 = dm[(i0+5)+nao*(k0+0)];
            d_6 = dm[(i0+6)+nao*(k0+0)];
            d_7 = dm[(i0+7)+nao*(k0+0)];
            d_8 = dm[(i0+8)+nao*(k0+0)];
            d_9 = dm[(i0+9)+nao*(k0+0)];
            atomicAdd(vk+(j0+0)+nao*(l0+0), gout90*d_0+gout93*d_1+gout96*d_2+gout99*d_3+gout102*d_4+gout105*d_5+gout108*d_6+gout111*d_7+gout114*d_8+gout117*d_9);
            atomicAdd(vk+(j0+1)+nao*(l0+0), gout91*d_0+gout94*d_1+gout97*d_2+gout100*d_3+gout103*d_4+gout106*d_5+gout109*d_6+gout112*d_7+gout115*d_8+gout118*d_9);
            atomicAdd(vk+(j0+2)+nao*(l0+0), gout92*d_0+gout95*d_1+gout98*d_2+gout101*d_3+gout104*d_4+gout107*d_5+gout110*d_6+gout113*d_7+gout116*d_8+gout119*d_9);
            atomicAdd(vk+(j0+0)+nao*(l0+0)+nao2, gout120*d_0+gout123*d_1+gout126*d_2+gout129*d_3+gout132*d_4+gout135*d_5+gout138*d_6+gout141*d_7+gout144*d_8+gout147*d_9);
            atomicAdd(vk+(j0+1)+nao*(l0+0)+nao2, gout121*d_0+gout124*d_1+gout127*d_2+gout130*d_3+gout133*d_4+gout136*d_5+gout139*d_6+gout142*d_7+gout145*d_8+gout148*d_9);
            atomicAdd(vk+(j0+2)+nao*(l0+0)+nao2, gout122*d_0+gout125*d_1+gout128*d_2+gout131*d_3+gout134*d_4+gout137*d_5+gout140*d_6+gout143*d_7+gout146*d_8+gout149*d_9);
            atomicAdd(vk+(j0+0)+nao*(l0+0)+2*nao2, gout150*d_0+gout153*d_1+gout156*d_2+gout159*d_3+gout162*d_4+gout165*d_5+gout168*d_6+gout171*d_7+gout174*d_8+gout177*d_9);
            atomicAdd(vk+(j0+1)+nao*(l0+0)+2*nao2, gout151*d_0+gout154*d_1+gout157*d_2+gout160*d_3+gout163*d_4+gout166*d_5+gout169*d_6+gout172*d_7+gout175*d_8+gout178*d_9);
            atomicAdd(vk+(j0+2)+nao*(l0+0)+2*nao2, gout152*d_0+gout155*d_1+gout158*d_2+gout161*d_3+gout164*d_4+gout167*d_5+gout170*d_6+gout173*d_7+gout176*d_8+gout179*d_9);
            // ijkl, il -> jk
            d_0 = dm[(i0+0)+nao*(l0+0)];
            d_1 = dm[(i0+1)+nao*(l0+0)];
            d_2 = dm[(i0+2)+nao*(l0+0)];
            d_3 = dm[(i0+3)+nao*(l0+0)];
            d_4 = dm[(i0+4)+nao*(l0+0)];
            d_5 = dm[(i0+5)+nao*(l0+0)];
            d_6 = dm[(i0+6)+nao*(l0+0)];
            d_7 = dm[(i0+7)+nao*(l0+0)];
            d_8 = dm[(i0+8)+nao*(l0+0)];
            d_9 = dm[(i0+9)+nao*(l0+0)];
            atomicAdd(vk+(j0+0)+nao*(k0+0), gout90*d_0+gout93*d_1+gout96*d_2+gout99*d_3+gout102*d_4+gout105*d_5+gout108*d_6+gout111*d_7+gout114*d_8+gout117*d_9);
            atomicAdd(vk+(j0+1)+nao*(k0+0), gout91*d_0+gout94*d_1+gout97*d_2+gout100*d_3+gout103*d_4+gout106*d_5+gout109*d_6+gout112*d_7+gout115*d_8+gout118*d_9);
            atomicAdd(vk+(j0+2)+nao*(k0+0), gout92*d_0+gout95*d_1+gout98*d_2+gout101*d_3+gout104*d_4+gout107*d_5+gout110*d_6+gout113*d_7+gout116*d_8+gout119*d_9);
            atomicAdd(vk+(j0+0)+nao*(k0+0)+nao2, gout120*d_0+gout123*d_1+gout126*d_2+gout129*d_3+gout132*d_4+gout135*d_5+gout138*d_6+gout141*d_7+gout144*d_8+gout147*d_9);
            atomicAdd(vk+(j0+1)+nao*(k0+0)+nao2, gout121*d_0+gout124*d_1+gout127*d_2+gout130*d_3+gout133*d_4+gout136*d_5+gout139*d_6+gout142*d_7+gout145*d_8+gout148*d_9);
            atomicAdd(vk+(j0+2)+nao*(k0+0)+nao2, gout122*d_0+gout125*d_1+gout128*d_2+gout131*d_3+gout134*d_4+gout137*d_5+gout140*d_6+gout143*d_7+gout146*d_8+gout149*d_9);
            atomicAdd(vk+(j0+0)+nao*(k0+0)+2*nao2, gout150*d_0+gout153*d_1+gout156*d_2+gout159*d_3+gout162*d_4+gout165*d_5+gout168*d_6+gout171*d_7+gout174*d_8+gout177*d_9);
            atomicAdd(vk+(j0+1)+nao*(k0+0)+2*nao2, gout151*d_0+gout154*d_1+gout157*d_2+gout160*d_3+gout163*d_4+gout166*d_5+gout169*d_6+gout172*d_7+gout175*d_8+gout178*d_9);
            atomicAdd(vk+(j0+2)+nao*(k0+0)+2*nao2, gout152*d_0+gout155*d_1+gout158*d_2+gout161*d_3+gout164*d_4+gout167*d_5+gout170*d_6+gout173*d_7+gout176*d_8+gout179*d_9);
            vk += 3*nao2;
        }
        dm += nao2;
    }
}
